//<![CDATA[

    if (GBrowserIsCompatible()) {
      var side_bar_html = "";
      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 icon = new GIcon();
icon.image = "http://www.bouwmij-janssen.nl/img/marker.png";
icon.iconSize = new GSize(45, 50);
icon.iconAnchor = new GPoint(6, 0);
icon.infoWindowAnchor = new GPoint(5,1);
        var marker = new GMarker(point, icon);
var html = "<div align=left style=line-height:11px; font-size:10px;><table cellpadding=0 cellspacing=0 border=0 width=400><tr><td valign=top width=200><b>Bouwmij Janssen</b><br>Keizersveld 28, 5803 AN Venray<br>Postbus 2, 5800 AA Venray</td><td valign=top align=right><img src=http://www.bouwmij-janssen.nl/img/logo.jpg></td></tr><tr><td valign=top colspan=2>T (0478) 55 44 55 - F (0478) 55 44 50<br><a href=mailto:info@bouwmij-janssen.nl>info@bouwmij-janssen.nl</a> - <a href=http://www.bouwmij-janssen.nl>www.bouwmij-janssen.nl</a><br><br></td></tr></table></div>";
var name = "Bouwmij Janssen";
        // The info window version with the "to here" form open
        to_htmls[i] = html + 'Route: <b>naar Bouwmij Janssen</b> - <a href="javascript:fromhere(' + i + ')">vanaf Bouwmij Janssen</a></div>' +
           '<br>Startpunt (straat, plaatsnaam):<form action="javascript:getDirections()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Maak routebeschrijving" TYPE="SUBMIT">' +
           '<input type="hidden" id="daddr" value="'+name+"@"+ point.lat() + ',' + point.lng() + 
           '"/>';
        // The info window version with the "to here" form open
        from_htmls[i] = html + 'Route: <a href="javascript:tohere(' + i + ')">naar Bouwmij Janssen</a> - <b>vanaf Bouwmij Janssen</b>' +
           '<br>Eindpunt (straat, plaatsnaam):<form action="javascript:getDirections()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Maak routebeschrijving" TYPE="SUBMIT">' +
           '<input type="hidden" id="saddr" value="'+name+"@"+ point.lat() + ',' + point.lng() +
           '"/>';
        // The inactive version of the direction info
        html = html + 'Route: <a href="javascript:tohere('+i+')">Naar Bouwmij Janssen</a> - <a href="javascript:fromhere('+i+')">Vanaf Bouwmij Janssen</a>';

        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        htmls[i] = html;
        // add a line to the side_bar html
        //side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
        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].openInfoWindowHtml(htmls[i]);
      }

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


      // create the map
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl(true));
      map.setCenter(new GLatLng(51.54054, 5.98862), 15);

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

      // === Array for decoding the failure codes ===
      var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Ok";
      reasons[G_GEO_MISSING_ADDRESS]    = "Adres niet bekend: Er was geen adres of het was niet bekend.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Adres niet bekend:  Dit adres werd niet gevonden.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Onbereikbaar adres:  Het opgegeven adres kan niet worden getoond vanwege onbekende redenen.";
      reasons[G_GEO_BAD_KEY]            = "Verkeerde Key: De API key is niet juist";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Te veel aanvragen: De dagelijks toegestane aantal aanvragen is al bereikt.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error";
      reasons[G_GEO_BAD_REQUEST]        = "De route aanvraag was niet succesvol.";
      reasons[G_GEO_MISSING_QUERY]      = "er is geen adres ingevoerd.";
      reasons[G_GEO_UNKNOWN_DIRECTIONS] = "Het GDirections object kon geen route maken tussen de punten.";

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

        alert("Route plannen mislukt, "+reason);
      });



      // Read the data from example.xml
            var lat = 51.54054;
            var lng = 5.98862;
            var point = new GLatLng(lat,lng);
            // create the marker
            var marker = createMarker(point);
            map.addOverlay(marker);
    }

    else {
      alert("Sorry, de Google Maps API is niet compitabel met deze browser");
    }
    //]]>
