if (GBrowserIsCompatible()) {
      var gmarkers = [];
      var htmls = [];
      var i = 0;
      // arrays to hold variants of the info window html with get direction forms open
      var to_htmls = [];
      var from_htmls = [];



      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
      	var myIcon = new GIcon();
      	myIcon.image = '/img/markers/image.png';
      	myIcon.printImage = '/img/markers/printImage.gif';
      	myIcon.mozPrintImage = '/img/markers/mozPrintImage.gif';
      	myIcon.iconSize = new GSize(26,37);
      	myIcon.shadow = '/img/markers/shadow.png';
      	myIcon.transparent = '/img/markers/transparent.png';
      	myIcon.shadowSize = new GSize(45,37);
      	myIcon.printShadow = '/img/markers/printShadow.gif';
      	myIcon.iconAnchor = new GPoint(13,37);
      	myIcon.infoWindowAnchor = new GPoint(13,0);
      	myIcon.imageMap = [25,0,25,1,25,2,25,3,25,4,25,5,25,6,25,7,25,8,25,9,25,10,25,11,25,12,25,13,25,14,25,15,25,16,25,17,25,18,25,19,25,20,25,21,25,22,25,23,25,24,25,25,17,27,17,28,17,29,16,30,15,31,15,32,14,33,14,34,13,35,13,36,12,36,12,35,11,34,11,33,10,32,10,31,9,30,8,29,8,28,8,27,0,25,0,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,0,1,0,0];
      	var marker = new GMarker(point, myIcon);
      			
      	//var html_contact = "<div class=adres><b>Pieter Brueghel kunst &amp; cultuur</b><br />Middegaal 23-25<br />5461 XB Veghel<br />Tel.: (0413) 365 675<br />Fax: (0413) 354 907<br />E-mail: <a href=\"mailto:info@pieterbrueghel.nl\">info@pieterbrueghel.nl</a> </div>";
      	//var name = "Pieter Brueghel kunst &amp; cultuur";
      	var html_route = "";
      	to_htmls[i] = html_route + '<div class="route"><strong>Route:</strong><br />Hier naartoe<br /><a href="javascript:fromhere(' + i + ')">Hier vandaan</a><br />' +
      		 '<strong>Startpunt (straat, plaats, land):</strong><form action="javascript:getDirections()">' +
      		 '<input type="text" size=40 maxlength=40 name="saddr" id="saddr" value="" />' +
      		 '<input value="Maak route &raquo;" type="submit" class="send_btn">' +
      		 '<input type="hidden" id="daddr" value="'+name+"@"+ point.lat() + ',' + point.lng() + 
      		 '"/></div>';
      	from_htmls[i] = html_route + '<div class="route"><strong>Route:</strong><br /><a href="javascript:tohere(' + i + ')">Hier naartoe</a><br />Hier vandaan<br />' +
      		 '<strong>Eindpunt (straat, plaats, land):</strong><form action="javascript:getDirections()">' +
      		 '<input type="text" size=40 maxlength=40 name="daddr" id="daddr" value="" />' +
      		 '<input value="Maak route &raquo;" type="submit" class="send_btn">' +
      		 '<input type="hidden" id="saddr" value="'+name+"@"+ point.lat() + ',' + point.lng() +
      		 '"/></div>';
      	html_route = html_route + '<div class="route"><strong>Route:</strong><br /><a href="javascript:tohere('+i+')">Hier naartoe</a><br /><a href="javascript:fromhere('+i+')">Hier vandaan</a><br /></div>';
      			
      	var infoTabs = [new GInfoWindowTab("Contact", html), new GInfoWindowTab("Route", html_route)]; 
      	//marker.openInfoWindowTabsHtml(infoTabs);
      	
      	GEvent.addListener(marker, "click", function() {
      		marker.openInfoWindowTabsHtml(infoTabs);
      	});
      			
      	gmarkers[i] = marker;
      	htmls[i] = infoTabs;
      	i++;
      	return marker;

      }

      // ===== request the directions =====
      function getDirections() {
        var saddr = document.getElementById("saddr").value
        var daddr = document.getElementById("daddr").value
        gdir.load("from: "+saddr+" to: "+daddr);
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowTabsHtml(htmls[i]);
      }

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


      // create the map
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(51.6264471, 5.5378625), 10);

      // === create a GDirections Object ===
      var gdir=new GDirections(map, document.getElementById("directions"));

      // === Array for decoding the failure codes ===
      var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
      reasons[G_GEO_BAD_REQUEST]        = "A directions request could not be successfully parsed.";
      reasons[G_GEO_MISSING_QUERY]      = "No query was specified in the input.";
      reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";

      // === catch Directions errors ===
      GEvent.addListener(gdir, "error", function() {
        var code = gdir.getStatus().code;
        var reason="Code "+code;
        if (reasons[code]) {
          reason = reasons[code]
        } 

        alert("Failed to obtain directions, "+reason);
      });



      // Read the data from example.xml
      var request = GXmlHttp.create();
      request.open("GET", "/xml/googlemaps-markers.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          // obtain the array of markers and loop through it
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");

          for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            // create the marker
            var marker = createMarker(point,label,html);
            map.addOverlay(marker);
          }
        }
      }
      request.send(null);
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

