var map;

function Directions(start, finish) {
	directionsPanel = document.getElementById("map_route");
	directions = new GDirections(map, directionsPanel);
	directions.load("from: " + start + " to: " + finish);
}

function moveTo(coord1, coord2) {
	//map.panTo(new GLatLng(coord1, coord2));
	map.setCenter(new GLatLng(coord1, coord2), 15);
}

function openBubble() {
	map.openInfowWindowHtml("TEST");
}

function load() {
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.shadowSize = new GSize(37, 30);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);

	function Wheel(a) { 
		if (a.cancelable) a.preventDefault(); 
		if (a.detail || -a.wheelDelta) { 
			var m = map.fromLatLngToDivPixel(new GLatLng(cursorlat,cursorlng)); 
			var c = map.fromLatLngToDivPixel(map.getCenter()); 
			
			if ((a.detail || -a.wheelDelta) < 0) { 
				var x = c.x - ((m.x - c.x) * -.5); 
				var y = c.y - ((m.y - c.y) * -.5); 
				var n = map.fromDivPixelToLatLng(new GPoint(x,y)); 
				map.setCenter(n); 
				map.zoomIn(); 
			} else if ((a.detail || -a.wheelDelta) > 0) { 
				var x = c.x - (m.x - c.x); 
				var y = c.y - (m.y - c.y); 
				var n = map.fromDivPixelToLatLng(new GPoint(x,y)); 
				map.setCenter(n); 
				map.zoomOut(); 
			}
		}
	}
	
	function createMarker(coord1, coord2, image, dsoft, html) {
		baseIcon.iconSize = (dsoft > 0) ? new GSize(35, 40) : new GSize(25, 30);

		var icon = new GIcon(baseIcon);
		if (image != '' || image) {
			icon.image = '/images/' + image;
		} else {
			icon.image = '/images/' + ((dsoft > 0) ? 'featured.png' : 'marker.png');
		}

		var m = new GMarker(new GLatLng(coord1, coord2), { icon:icon });
		GEvent.addListener(m, 'click', function() { m.openInfoWindowHtml(html); });
		return m;
	}

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		var m;
		var cursorlat; 
		var cursorlng; 
		

		map.setCenter(new GLatLng(33.759974,-117.839642), 11);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		
		
m = createMarker(33.759974,-117.839642, '', 0, '<h1><div class="dispName">Go N Green</div></h1><div class="dispAddress">1905 17th St. Suite 201</div><b>Phone</b><div class="dispPhone">(714) 766-0420</div><b>Hours</b><div class="dispHours">Call for hours.</div><b>Directions</b> <input id="address" ><button onclick="return Directions(document.getElementById(&quot;address&quot;).value, &quot;1905 17th St. Santa Ana CA 92705&quot;);">Get Directions</button>');map.addOverlay(m);


		GEvent.addDomListener(document.getElementById('map_canvas'), 'mousewheel', Wheel); 
		GEvent.addDomListener(document.getElementById('map_canvas'), 'DOMMouseScroll', Wheel);
		GEvent.addListener(map, 'mousemove', function(point) { cursorlat = point.y.toFixed(6); cursorlng = point.x.toFixed(6); }); 
	}
}