google.load("maps", "2.x");   

var map = null;
var id = '';
var locations = [];


function createMarker(point, markerOptions, location) {
	var marker = new GMarker(point, markerOptions);
	GEvent.addListener(marker, 'click', function() {
		var myHtml = '<strong>Wok to Walk</strong><br/>' + location.description;
		map.openInfoWindowHtml(point, myHtml);
	});
	return marker;
}

function initialize() {
	if ((id != '') && (locations.length != 0)) {
		var isActive = false;
		var activeLocation = 0;
		for (var i=0; i<locations.length; i++) {
			loc = locations[i];
			if (loc.id.toLowerCase() == id.toLowerCase()) { 
				activeLocation = i;
				isActive = true;
			}
		}
		
		if (isActive) {
			var baseIcon = new GIcon();
			baseIcon.iconSize = new GSize(20, 24);
			baseIcon.iconAnchor = new GPoint(20, 23);
			baseIcon.infoWindowAnchor = new GPoint(19, 2);
			baseIcon.shadow = "/media/gmaps/marker_shadow.png";
			baseIcon.shadowSize = new GSize(34, 23);
			baseIcon.infoShadowAnchor = new GPoint(19, 23);
			
			var baseIcon2 = new GIcon();
			baseIcon2.iconSize = new GSize(39, 46);
			baseIcon2.iconAnchor = new GPoint(38, 44);
			baseIcon2.infoWindowAnchor = new GPoint(19, 2);
			baseIcon2.shadow = "/media/gmaps/marker_active_shadow.png";
			baseIcon2.shadowSize = new GSize(67, 46);
			baseIcon2.infoShadowAnchor = new GPoint(40, 46);
			
			var mIcon = new GIcon(baseIcon);
			mIcon.image = "/media/gmaps/marker.png";
			markerOptions = { icon:mIcon };
			
			var mIcon2 = new GIcon(baseIcon2);
			mIcon2.image = "/media/gmaps/marker_active.png";
			activeMarkerOptions = { icon:mIcon2 };
			
			map = new google.maps.Map2(document.getElementById("map")); 
			map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 15);  
			map.addControl(new GLargeMapControl());
			// map.addControl(new GMapTypeControl());
			
			for (var i=0; i<locations.length; i++) {
				loc = locations[i];
				if (loc.id.toLowerCase() != id.toLowerCase()) {
					point = new GLatLng(loc.lat, loc.lng);
					map.addOverlay(createMarker(point, markerOptions, loc));
				}
			}
			
			// add active icon last
			loc = locations[activeLocation];
			point = new GLatLng(loc.lat, loc.lng);
			map.addOverlay(createMarker(point, activeMarkerOptions, loc));
			map.setCenter(point, 13); 
		} else {
			document.getElementById('mapWrapper').style.display = 'none';
		}
	} else {
		document.getElementById('mapWrapper').style.display = 'none';
	}
}  

google.setOnLoadCallback(initialize);




