
var map = null;
var geoXml = null;
var hotXml = null;

function initPage() {
	if (!GBrowserIsCompatible()) {
		alert("Your browser may not be compatible with the Google Maps system.\nPlease visit http://maps.google.com for more information.");
	} else {
		map = new GMap2(document.getElementById("kaartje"));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(52.22 ,6.90), 13);
		map.addControl(new GMapTypeControl());
	}
}

 function handleRequest(req) {
        var writeroot = document.getElementById('right');
        writeroot.innerHTML = req.responseText;
}


window.onunload=GUnload;
window.onload=initPage;

fetch_unix_timestamp = function()
{
	return parseInt(new Date().getTime().toString().substring(0, 10))
}

function loadMap(mapurl,mapnr,zoom) {
	map.clearOverlays();

	geoXml = new GGeoXml(mapurl,
		function () {
			map.setCenter(geoXml.getDefaultCenter(), zoom);
			map.addOverlay(geoXml);
		}
	);

	var datastream = 'http://www.enschedebuitensporig.nl/hotspots/geodata.kml?mapnr='+mapnr+'&t='+fetch_unix_timestamp();

	hotXml = new GGeoXml(datastream,
		function () {
			map.addOverlay(hotXml);
/*
	 hack to stop the links in the popup balloon from targeting an other window..
*/

			GEvent.addListener(map,"infowindowopen",function() {
                		var i = map.getInfoWindow();
                		var nodes = i.getContentContainers();
                		for (var node in nodes) {
                        		var anchors = nodes[node].getElementsByTagName('A');
                        		for (var a in anchors) {
                                		if (anchors[a].tagName) {
                                        		anchors[a].setAttribute("target","hotspots");
						}
					}
                		}
        		});
		}
	);

	var infostream = 'http://www.enschedebuitensporig.nl/hotspots/ajax.info?mapnr='+mapnr;
	sendRequest(infostream,handleRequest);
}


function addMap(mapnr) {
	var datastream = 'http://www.enschedebuitensporig.nl/hotspots/geodata.kml?mapnr='+mapnr;
	hotXml = new GGeoXml(datastream,
		function () {
			map.addOverlay(hotXml);
		}
	);
}
