if (GBrowserIsCompatible()) { 
	// A function to create the marker and set up the event window
	// Dont try to unroll this function. It has to be here for the function closure
	// Each instance of the function preserves the contends of a different instance
	// of the "marker" and "html" variables which will be needed later when the event triggers.    
	function createMarker(point,html,label) {
		var marker = new GMarker(point);


		GEvent.addListener(marker, "click", function() {
			html2 = bubbleContent(html,label);
			marker.openInfoWindowHtml(html2);
			storeMarker = marker;
			storePoint = point;
			timer = setTimeout("planRoute()", 1000);
		});
		return marker;
	}
	
	var storePoint = '';
	var storeMarker = '';
	
	function planRoute() {
		
		$('.adres').bind('keypress', function(e) {
			if (e.which == 32) {
				return false;
			}
		});
		
		var gdir;
		
		$(".bt").bind("click", pl = function(e){
			var saddr = $("#adres").val();
			var opts = {locale:"nl"};
			gdir = new GDirections(map, document.getElementById("route"));
			saddr = saddr.replace(" ", "+");
			saddr = saddr + '+Nederland';
			gdir.load("from: "+saddr+" to: " + storePoint, opts);
			// GEvent.addListener(gdir, 'error', handleErrors(gdir));
			storeMarker.closeInfoWindow();
		});
		clearTimeout(timer);
	}
	function bubbleContent(html,label) {
		value = '';
		value += '<div class="bubbleContent" style="width:450px;">';
		value += '<h4 style="font-size:14px;">' + label + '</h4>';
		value +=  html;
		value += '<h4>Plan een route naar dit adres:</h4>';
		value += '<div style="height:20px;"><hr /><form action="#" method="get" onsubmit="pl(); return false"><div style="width:235px;float:left;"><input onfocus="clearText(this)" style="margin:0; padding:0; border:solid 1px #BBB;;width:230px;height:20px;" id="adres" name="adres" type="text" value="Uw adres en/of postcode"/></div><div style="width:100px;float:left;"><input class="bt" style="margin-left:5px;border:solid 1px #BBB;width:60px;height:22px;" name="route" type="button" value="route"/></div></form></div>';
		value += '</div>';
		return value;
	}
	

	// Display the map, with some controls and set the initial location 
	function writemap() {
		map = new GMap2(document.getElementById("kaart"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(52.63236,4.75068),12);
	}
	
	function handleErrors(gdir){
		alert('Een route tussen deze twee locaties kon niet worden berekend.');
		/*if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		{
			alert("De locatie van het opgegeven vertrekadres kon niet worden bepaald.nFoutcode: " + gdir.getStatus().code);
		}
		else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		{
			alert("Er is iets misgegaan. Maar het is onduidelijk WAT!n Foutcode: " + gdir.getStatus().code);
		}
		else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		{
			alert("Een parameter ontbreekt. Misschien was er geen vertrekpunt ingevoerd.n Foutcode: " + gdir.getStatus().code);
		}
		else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		{
			alert("De Google Maps sleutel is ongeldig of de gebruikte sleutel is niet geldig voor dit domein. n Foutcode: " + gdir.getStatus().code);
		}
		else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		{
			alert("De aanvraag voor het plannen van een route is mislukt.n Foutcode: " + gdir.getStatus().code);
		}
		else
		{
			alert("Er is iets misgegaan. Maar het is volstrekt onduidelijk wat de oorzaak is!");
		}*/
	}


} else {
	alert("Excusses, de Google Maps API is niet compatible met uw browser");
}
	// This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://econym.googlepages.com/index.htm
	gmarkers = [];
	var map = '';
	var bounds = new GLatLngBounds();
	
$().ready(function() {
	// Bepaal de hoogte van de kaart container.
	//$("#kaart").css("height", "450px");
	// Schrijf de kaart naar het scherm.
	writemap();
	
	// HACK
	// Op de google map worden een aantal "no-print" ellement getoverd.
	// Deze blokeren de navigatie met de hand-cursor op de kaart.
	// daarom maken we ze een stuk kleiner, zodat we er geen last meer van hebben.
	// $(".gmnoprint").css("border", "solid 1px red"); // uncomment deze regel om de "no-print" area's zichtbaar te maken. 
	$(".gmnoprint").css("width", "5px");
	$(".gmnoprint").css("height", "30px");
	// END HACK
	
	// Loop door de data arrays, en creeer markers, op de kaart.
	for (c = 0; c < lats.length; c++ ) {
		var point = new GLatLng(lats[c],longs[c]);
		var marker = createMarker(point,htmls[c],labels[c]);
		map.addOverlay(marker);
		
		gmarkers.push(point);
		bounds.extend(point);
		map.setZoom(map.getBoundsZoomLevel(bounds));
		map.setCenter(bounds.getCenter());
	}
	//$('#mtgt_unnamed_0').fireEvent('onClick');
	
	// Haal een instantie op van de GDirections, om routes mee te bepalen.
	var opts = {locale:"nl"};
	/*if (document.getElementById("walk").checked) {
		opts.travelMode = G_TRAVEL_MODE_WALKING;
	}
	if (document.getElementById("highways").checked) {
		opts.avoidHighways = true;
	}*/

	// ==== set the start and end locations ====
});