// Google maps functions //

var map;
var baseIcon;

function mapSetup() {
	// Runs new map and adds controls
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		//alert("map:"+map);
		// add movement and zoom controls
		map.addControl(new GSmallMapControl());
		// add map type switching
		map.addControl(new GMapTypeControl());
		// add map overview switching
		map.addControl(new GOverviewMapControl());
		// coordinate listener
		//GEvent.addListener(map, "moveend", function() {
			//get centre of the map
			//var center = map.getCenter();
			// gets individual coordinates
			//var mapLat = center.lat();
			//var mapLng = center.lng();
		//});
		// Create a base icon for all of our markers that specifies the shadow, icon dimensions, etc.
		baseIcon = new GIcon();
		baseIcon.image = "/images/leightons_marker.png";
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);
	}
}

// sets center point and zoom depth
function CenterMap(mapLat,mapLong,mapZoom) {
	map.setCenter(new GLatLng(mapLat, mapLong), mapZoom);
}

// move map to new coordinates
function MapMove(newMapLat,newMapLng) {
	// pan from one element to another
	window.setTimeout(function() {
	map.panTo(new GLatLng(newMapLat, newMapLng));
	// delay
	}, 0);

}

function CreateMarker(newMarkerLat,newMarkerLong,newMarkerHtml) {
	// Creates a marker at the given point with the given html
	var icon = new GIcon(baseIcon);
	var point = new GLatLng(newMarkerLat,newMarkerLong);
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(newMarkerHtml);
	});
	map.addOverlay(marker);
}

