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()", 500);
		});
		
		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;
		
		$("#rpbt").bind("click", function(e){
			$(".routeText").show();
			$(".routeTitle").show();
			$("#myroute").show();
			var saddr = $("#adres").val();
			var opts = {locale:"nl"};
			gdir = new GDirections( map, document.getElementById("myroute") );
			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: 340px; height: 90px;">';
		value += '<h4 style="font-size:14px;">' + label + '</h4>';
		value +=  html;
		value += '<h5 style="font-size:10px;">Vul uw postcode in en plan een route naar dit adres:</h5>';
		value += '<div style="height:20px;"><hr style="margin-bottom:5px;" /><form action="#" method="get" onsubmit="return false"><div style="float:left;width:210px;"><input onfocus="" style="padding:3px 2px 0 3px; border:solid 1px #BBB;width:200px;height:17px;" id="adres" name="adres" type="text" value="'+bubblePostcode+'"/></div><div style="float:left;width:85px;"><input class="bt" id="rpbt" style="border:none;width:82px;height:23px;background: url(images/planroute.gif) no-repeat scroll 0 0;" name="route" type="button" value=""/></div></form></div>';
		value += '</div>';
		return value;
	}
	
	function clearText(e)
	{
		$(e).val('');
	}
	// Display the map, with some controls and set the initial location 
	function writemap()
	{
		map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(52.768828, 4.662327),12);
	}
	
	function handleErrors(gdir)
	{
		alert('Een route tussen deze twee locaties kon niet worden berekend.');
	}


}
else
{
	alert("Excuses, 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 ====
});