  //<![CDATA[
	
/* Error messages for possible errors */
		var error_address_empty 	= 'Voer een geldig adres in.';
		var error_invalid_address 	= 'Het ingevoerde adres is ongeldig. Controleer of u het huisnummer en woonplaats correct heeft ingevuld.'; 
		var error_google_error 		= 'De zoekopdracht kon niet worden verwerkt, probeer het nogmaals.';
		var error_no_map_info		= 'Map informatie is niet beschikbaar voor dit adres. Excuses voor het ongemak.';
		
		/**********************************************************************************************************************/
		/* CHANGE THIS TO YOUR ADDRESS - The default address of your store, This address will display on the map on startup */
		/**********************************************************************************************************************/
		var default_address = 'Ploegstraat 4 3319 LG Dordrecht';
		var current_address = null; /* Current address we are displaying, we save it here for directions */
		var map				  = null; /* Instance of Google Maps object */
		var geocoder		  = null; /* Instance of Google Deocoder object */
		var gdir				  = null; /* Instance of Google Directions object */
		var map_compatible  = false; /* Whether or not user's browser is compatible to show the map */

		/* Check if the browser is compatible */
		if( GBrowserIsCompatible() ) {
			map_compatible = true;
		}

		/* Initialize the map this will be called when the document is loaded from: <body onLoad="initialize_map();"> */
		function initialize_map() {
			if( map_compatible ) {
				map = new GMap2(document.getElementById("map"));    
				geocoder = new GClientGeocoder();
				show_address(default_address);
				map.addControl(new GLargeMapControl3D());
				map.addControl(new GMenuMapTypeControl(true,false));
				// map.enableScrollWheelZoom();
				// map.addControl(new GSmallZoomControl3D());
				// map.addControl(new GOverviewMapControl());
			}
		}
		
		/* This function will move the map and shows the address passed to it */
		function show_address(address) {
			if( map_compatible && geocoder ) {
				/* Save this address in current_address value to use later if user wants directions */
				current_address = address;		
				geocoder.getLatLng(
				address,
				function( point ) {
					if( !point ) {
						alert(error_no_map_info);
					} else {
						map.setCenter(new GLatLng(51.7957,4.7157), 14); //51.794211,4.664361
					
						  var point = new GLatLng(51.7957,4.7157);
						  var marker = new GMarker(point);
						  map.addOverlay(marker);
						  marker.openInfoWindowHtml("<font size='2' color='#000000' style='verdana'><b>AAO Adviesgroep bv</b><br><br>Ploegstraat 4<br>3319 LG Dordrecht<br><a href='http://www.aao.nl' target='_blank' style='text-decoration:none;'><font color='#000000'>www.aao.nl</font><\/a><br>");
					}
				}
				);
			}
			return false;
		}
		
		/* Get the directions */
		function get_directions() {
			if( map_compatible ) {
				if( document.direction_form.from_address.value == '' ) {
					alert(error_address_empty);
					return false;
				}
				document.getElementById('directions').innerHTML = '';
				
				gdir = new GDirections(map, document.getElementById('directions'));
				
				/* Setup to event handlers, one: when the directions are loaded, two: if there was any error */
				GEvent.addListener(gdir, 'load',  onGDirectionsLoad);
				GEvent.addListener(gdir, 'error', handleErrors);
				
				/* Show the directions */
				set_directions(document.direction_form.from_address.value, current_address);			
			}
			return false;
		}
		
		/* This will actually set the directions on the map and loads the direction table */
		function set_directions(fromAddress, toAddress) {
      	gdir.load("from: " + fromAddress + " to: " + toAddress,
                	{ "locale": "nl" });
    	}
		
		/* This will handle the errors might happen while retrieving the directions */
		function handleErrors(){
			if( gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS )
				alert(error_invalid_address);
			else if( gdir.getStatus().code == G_GEO_SERVER_ERROR )
				alert(error_google_error);
			else if( gdir.getStatus().code == G_GEO_MISSING_QUERY )
				alert(error_address_empty);
			else 
				alert(error_invalid_address);
		}
		
		/* This function will be called when the directions are loaded */
		function onGDirectionsLoad(){
			/* We will simple scroll down to the directions, but with a little delay so it's loaded */
			setTimeout('eval(\'\')', 500);
			/* setTimeout('eval(\'window.location = "#route"\;\')', 500); */
		}

		// Check to see if this browser can run the Google API
    if (GBrowserIsCompatible()) {

      var gmarkers = [];
      var htmls = [];
      var to_htmls = [];
      var from_htmls = [];
      var i=0;
	  
      // A function to create the marker and set up the event window
      function createMarker(point,name,html,icon) {

        // The info window version with the "to here" form open
        to_htmls[i] = html + '<br>Route: <b><font color="#000000">Hier naartoe</font><\/b> - <a href="javascript:fromhere(' + i + ')"><font color="#000000">Hier vandaan</font><\/a>' +
           '<br><br><form action="http://maps.google.com/maps" method="get" target="_blank"> Start adres: <input type="text" SIZE=15 MAXLENGTH=40 name="saddr" id="saddr" value="" /> ' +
           '<INPUT value="Bereken" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
                  // "(" + name + ")" + 
           '"/>';
        // The info window version with the "to here" form open
        from_htmls[i] = html + '<br>Route: <a href="javascript:tohere(' + i + ')"><font color="#000000">Hier naartoe</font><\/a> - <b><font color="#000000">Hier vandaan</font><\/b>' +
           '<br><br><form action="http://maps.google.com/maps" method="get" target="_blank"> Eindbestemming: <input type="text" SIZE=15 MAXLENGTH=40 name="daddr" id="daddr" value="" /> ' +
           '<INPUT value="Bereken" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
                  // "(" + name + ")" + 
           '"/>';

        // The inactive version of the direction info
        html = html + '<br>Routebeschrijving: <a href="javascript:tohere('+i+')"><font color="#000000">Hier naartoe</font><\/a> - <a href="javascript:fromhere('+i+')"><font color="#000000">Hier vandaan</font><\/a>';

        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers[i] = marker;
        htmls[i] = html;
        i++;
        return marker;
      }

      // functions that open the directions forms
      function tohere(i) {
        gmarkers[i].openInfoWindowHtml(to_htmls[i]);
      }
      function fromhere(i) {
        gmarkers[i].openInfoWindowHtml(from_htmls[i]);
      }

      // Plaats Markers hieronder
    
    }

    // display a warning if the browser was not compatible
    else {
      alert("De Google Maps API kon niet geladen worden. Uw browser geeft geen ondersteuning. Excuses voor het ongemak.");
    }

    //]]>
