function load(){
	if (GBrowserIsCompatible()) { 
		map = new GMap2(document.getElementById("DivMap"));
		map.setCenter(new GLatLng(51.507416,-0.134454), 16);		
		map.addControl(new GMapTypeControl());
		map.addControl(new GLargeMapControl());
		map.addControl(new GOverviewMapControl(new GSize(150,100))); // undocumented

		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
	}
	
	// Display markers
	getMarkers();
	
	GEvent.addListener(map, "click", function(overlay, point) { 
		if (overlay && overlay.openInfoWindowHtml) { 
			overlay.openInfoWindowHtml(overlay.infowindow); 
		} else if (point) { 
			map.removeOverlay(overlay); 
		} 
	}); 
	
	infoOpened = false;
	
	function onInfoWindowOpen() { 
		infoOpened = true; 
	}
	
	function onInfoWindowClose() { 
		infoOpened = false; 
	}
	
	function onMapMoved() {
		
		var bounds = map.GLatLngBounds

		if( infoOpened == true ) { 
			infoOpened = true; 
			return; 
		}
		else {
			infoOpened = false;
		}
		map.clearOverlays(); 
		getMarkers();
	} 

	GEvent.addListener(map, "moveend", onMapMoved); 
	GEvent.addListener(map, "infowindowopen", onInfoWindowOpen);
	GEvent.addListener(map, "infowindowclose", onInfoWindowClose);
}

function getMarkers(){
	
	var bounds = map.getBounds();
	var mapsw = bounds.getSouthWest();
	var mapne = bounds.getNorthEast();
	var mapswlat = mapsw.lat();
	var mapswlong = mapsw.lng();
	var mapnelat = mapne.lat();
	var mapnelong = mapne.lng();

	var urlstr = "/xml/map_location.xml";
	
	// Make add new link and set default location
	var center = map.getCenter();
	var zoom = map.getZoom();

	var request = GXmlHttp.create();
	request.open("GET", urlstr , true);	// request XML from PHP with AJAX call
	request.onreadystatechange = function () {
		if (request.readyState == 4) {
			var xmlDoc = request.responseXML;
			locations = xmlDoc.documentElement.getElementsByTagName("location");
			markers = [];
			
			if (locations.length){
				for (var i = 0; i < locations.length; i++) { // cycle thru locations
					markers[i] = new GMarker(new GLatLng(locations[i].getAttribute("lat"),locations[i].getAttribute("lng")));
					// Add attributes to the marker so we can poll them later.
					// When clicked, an overlay will have these properties.
					markers[i].infowindow = locations[i].getAttribute("name");

					// Useful things to store on a marker (Not needed for this example, could be removed)
					// Tells you what index in the markers[] array an overlay is
					markers[i].markerindex = i;
					// Store the location_id of the location the marker represents.
					// Very useful to know the true id of a marker, you could then make
					// AJAX calls to the database to update the information if you had it's location_id
					markers[i].db_id = locations[i].getAttribute("location_id");

					map.addOverlay(markers[i]);
				}
			}
		}
	}
	request.send(null);
}
