// JScript File
//<![CDATA[
var map;
var point;
var marker;
var baseIcon = new GIcon();
baseIcon.iconSize=new GSize(24,38);
baseIcon.iconAnchor=new GPoint(24>>1,24>>1);
baseIcon.shadowSize=new GSize(24,38);
baseIcon.infoWindowAnchor=new GPoint(20,4);
var destIcon = new GIcon(baseIcon, "/images/map/map_pin.png", null, null);
var parkIcon = new GIcon(baseIcon, "/images/map/park-0.png", null, null);

function loadMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));	
		map.addControl(new GSmallMapControl());
		
		// Centerize the map before using
		map.setCenter(new GLatLng(0,0),0);
		
		// Start with an empty GLatLngBounds object
		var bounds = new GLatLngBounds();
		

		// Add destination icon
		point = new GLatLng(destination['lat'], destination['lng']);
		marker = new GMarker(point, {icon: destIcon, title: destination['title']});  
		map.addOverlay(marker);
		addDestMarkerEvents(marker,destination);
		bounds.extend(point);
		
		// Add parking icon
		if (parking['lat'] != undefined) {		
			point = new GLatLng(parking['lat'], parking['lng']);
			marker = new GMarker(point, {icon: parkIcon, title: parking['title']});
			map.addOverlay(marker);
			addDestMarkerEvents(marker,parking);
			bounds.extend(point);
		}
		// determine the zoom level from the bounds =====
		map.setZoom(map.getBoundsZoomLevel(bounds));

		// determine the centre from the bounds ======
		map.setCenter(bounds.getCenter());
	}
}

function addDestMarkerEvents(marker, destination)
{    
		GEvent.addListener(marker, 'click', function() { 
			var content = "<table border='0' cellpadding='0' cellspacing='0' style='color:#000;'><tr><td class='contentDirections'><b>" + destination['title'] + "</b></td></tr><tr><td><b>City:</b>&nbsp;" + destination['city'] + "</td></tr><tr><td><b>State:</b>&nbsp;" + destination['state'] + "</td></tr></table></div>";
			map.openInfoWindowHtml( marker.getLatLng(), content, {pixelOffset: new		GSize(10,10)} );
		} )
}

window.onload = loadMap;
window.onunload=GUnload;

//]]>