// Google maps functions //

var map;
var baseIcon;

var mapReady = false;

function mapSetup() {
	// Runs new map and adds controls
	if ((mapReady == false) && 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();
		//});
		var mapLat = 51.508105;
		var mapLon = -0.147899;
		CenterMap(mapLat, mapLon, 15);
		CreateMarker(mapLat, mapLon, "<strong>CKD Kennedy Macpherson Ltd</strong>");
		mapReady = true;
	}
}

// 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 point = new GLatLng(newMarkerLat, newMarkerLong);
	var marker = new GMarker(point);
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(newMarkerHtml);
	});
	
	map.addOverlay(marker);
}

