document.onload=StartTimer();

var timerID = null;


//<![CDATA[

function StartTimer()
{
	// start a timer for 2 seconds - should be long enough for the block to load and map div to be valid
	timerID = self.setTimeout("DoMap()", 2000);
}

// Creates a marker whose info window displays the given number
function createMarker(point, info)
{
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(info);} );
	return marker;
}

function DoMap()
{
	var markerinfo;
	//clear the timer now
	clearTimeout(timerID);
	var mapdiv = document.getElementById("map");
	if (mapdiv)
	{
		var map = new GMap(mapdiv);
		map.addControl(new GSmallMapControl());
		map.centerAndZoom(new GPoint(-0.2117013931274414,51.79760173954009), 3);
		//GEvent.addListener(map, 'click', function(overlay, point) { map.addOverlay(createMarker(point, "")); } );
		
		// add the markers from an xml file "markers.xml" in the root
		var request = GXmlHttp.create();
		request.open("GET", "markers.xml", true);

		request.onreadystatechange = function() {
		  if (request.readyState == 4) 
		  {

		    var xmlDoc = request.responseXML;
		    var markers = xmlDoc.documentElement.getElementsByTagName("marker");
		    for (var i = 0; i < markers.length; i++) 
		    {
			var point = new GPoint(parseFloat(markers[i].getAttribute("lng")),
					     parseFloat(markers[i].getAttribute("lat")));
			if (markers[i].childNodes.length >0)
			{
				markerinfo = markers[i].childNodes[0].nodeValue;
			}
			map.addOverlay(createMarker(point, markerinfo));
		    }
		  }
		}
		request.send(null);

	}
	// fail gracefully if no map div found
}

//]]>

