// arrays to hold copies of the markers and html used by the sidebar
      // because the function closure trick doesnt work there
      var gmarkers = [];

// global variables
      var map;
      var request;
	var bounds = new GLatLngBounds();

// This function picks up the click and opens the corresponding info window
      function myclick(i) {
         GEvent.trigger(gmarkers[i], "click");
      }


// Replaces the in-page window onload function
GEvent.addDomListener(window, "load", load);
GEvent.addDomListener(window, "unload", GUnload); 


function load() {
if (GBrowserIsCompatible()) {
      // this variable will collect the html which will eventualkly be placed in the sidebar
      var side_bar_html = "";


var icons = new Array();

// for 010191000010
icons["010191000010"] = new GIcon(); 
icons["010191000010"].image = "images/thumbs/010191000010.png"; 
icons["010191000010"].iconSize=new GSize(70, 70); 
icons["010191000010"].iconAnchor=new GPoint(30, 35); 
icons["010191000010"].infoWindowAnchor=new GPoint(30, 0);

// for 010191000367
icons["010191000367"] = new GIcon(); 
icons["010191000367"].image = "images/thumbs/010191000367.png"; 
icons["010191000367"].iconSize=new GSize(70, 70); 
icons["010191000367"].iconAnchor=new GPoint(35, 70); 
icons["010191000367"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000376
icons["010191000376"] = new GIcon(); 
icons["010191000376"].image = "images/thumbs/010191000376.png"; 
icons["010191000376"].iconSize=new GSize(70, 70); 
icons["010191000376"].iconAnchor=new GPoint(35, 70); 
icons["010191000376"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000480
icons["010191000480"] = new GIcon(); 
icons["010191000480"].image = "images/thumbs/010191000480.png"; 
icons["010191000480"].iconSize=new GSize(70, 70); 
icons["010191000480"].iconAnchor=new GPoint(35, 70); 
icons["010191000480"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000488
icons["010191000488"] = new GIcon(); 
icons["010191000488"].image = "images/thumbs/010191000488.png"; 
icons["010191000488"].iconSize=new GSize(70, 70); 
icons["010191000488"].iconAnchor=new GPoint(35, 70); 
icons["010191000488"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000496
icons["010191000496"] = new GIcon(); 
icons["010191000496"].image = "images/thumbs/010191000496.png"; 
icons["010191000496"].iconSize=new GSize(70, 70); 
icons["010191000496"].iconAnchor=new GPoint(35, 70); 
icons["010191000496"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000426
icons["010191000426"] = new GIcon(); 
icons["010191000426"].image = "images/thumbs/010191000426.png"; 
icons["010191000426"].iconSize=new GSize(70, 70); 
icons["010191000426"].iconAnchor=new GPoint(35, 70); 
icons["010191000426"].infoWindowAnchor=new GPoint(35, 0);


// for 030178000090
icons["030178000090"] = new GIcon(); 
icons["030178000090"].image = "images/thumbs/030178000090.png"; 
icons["030178000090"].iconSize=new GSize(70, 70); 
icons["030178000090"].iconAnchor=new GPoint(35, 70); 
icons["030178000090"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000543
icons["030178000543"] = new GIcon(); 
icons["030178000543"].image = "images/thumbs/030178000543.png"; 
icons["030178000543"].iconSize=new GSize(70, 70); 
icons["030178000543"].iconAnchor=new GPoint(35, 70); 
icons["030178000543"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000105
icons["010191000105"] = new GIcon(); 
icons["010191000105"].image = "images/thumbs/010191000105.png"; 
icons["010191000105"].iconSize=new GSize(70, 70); 
icons["010191000105"].iconAnchor=new GPoint(35, 70); 
icons["010191000105"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000037
icons["010191000037"] = new GIcon(); 
icons["010191000037"].image = "images/thumbs/010191000037.png"; 
icons["010191000037"].iconSize=new GSize(70, 70); 
icons["010191000037"].iconAnchor=new GPoint(35, 70); 
icons["010191000037"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000052
icons["010191000052"] = new GIcon(); 
icons["010191000052"].image = "images/thumbs/010191000052.png"; 
icons["010191000052"].iconSize=new GSize(70, 70); 
icons["010191000052"].iconAnchor=new GPoint(35, 70); 
icons["010191000052"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000260
icons["010191000260"] = new GIcon(); 
icons["010191000260"].image = "images/thumbs/010191000260.png"; 
icons["010191000260"].iconSize=new GSize(70, 70); 
icons["010191000260"].iconAnchor=new GPoint(35, 70); 
icons["010191000260"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000195
icons["030178000195"] = new GIcon(); 
icons["030178000195"].image = "images/thumbs/030178000195.png"; 
icons["030178000195"].iconSize=new GSize(70, 70); 
icons["030178000195"].iconAnchor=new GPoint(35, 70); 
icons["030178000195"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000443
icons["030178000443"] = new GIcon(); 
icons["030178000443"].image = "images/thumbs/030178000443.png"; 
icons["030178000443"].iconSize=new GSize(70, 70); 
icons["030178000443"].iconAnchor=new GPoint(35, 70); 
icons["030178000443"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001537
icons["030178001537"] = new GIcon(); 
icons["030178001537"].image = "images/thumbs/030178001537.png"; 
icons["030178001537"].iconSize=new GSize(70, 70); 
icons["030178001537"].iconAnchor=new GPoint(35, 70); 
icons["030178001537"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000449
icons["030178000449"] = new GIcon(); 
icons["030178000449"].image = "images/thumbs/030178000449.png"; 
icons["030178000449"].iconSize=new GSize(70, 70); 
icons["030178000449"].iconAnchor=new GPoint(35, 70); 
icons["030178000449"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000519
icons["030178000519"] = new GIcon(); 
icons["030178000519"].image = "images/thumbs/030178000519.png"; 
icons["030178000519"].iconSize=new GSize(70, 70); 
icons["030178000519"].iconAnchor=new GPoint(35, 70); 
icons["030178000519"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000182
icons["010191000182"] = new GIcon(); 
icons["010191000182"].image = "images/thumbs/010191000182.png"; 
icons["010191000182"].iconSize=new GSize(70, 70); 
icons["010191000182"].iconAnchor=new GPoint(35, 70); 
icons["010191000182"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000266
icons["010191000266"] = new GIcon(); 
icons["010191000266"].image = "images/thumbs/010191000266.png"; 
icons["010191000266"].iconSize=new GSize(70, 70); 
icons["010191000266"].iconAnchor=new GPoint(35, 70); 
icons["010191000266"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000359
icons["010191000359"] = new GIcon(); 
icons["010191000359"].image = "images/thumbs/010191000359.png"; 
icons["010191000359"].iconSize=new GSize(70, 70); 
icons["010191000359"].iconAnchor=new GPoint(35, 70); 
icons["010191000359"].infoWindowAnchor=new GPoint(35, 0);

// for 010191000410
icons["010191000410"] = new GIcon(); 
icons["010191000410"].image = "images/thumbs/010191000410.png"; 
icons["010191000410"].iconSize=new GSize(70, 70); 
icons["010191000410"].iconAnchor=new GPoint(35, 70); 
icons["010191000410"].infoWindowAnchor=new GPoint(35, 0);

// for 010193000504
icons["010193000504"] = new GIcon(); 
icons["010193000504"].image = "images/thumbs/010193000504.png"; 
icons["010193000504"].iconSize=new GSize(70, 70); 
icons["010193000504"].iconAnchor=new GPoint(35, 70); 
icons["010193000504"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000018
icons["030178000018"] = new GIcon(); 
icons["030178000018"].image = "images/thumbs/030178000018.png"; 
icons["030178000018"].iconSize=new GSize(70, 70); 
icons["030178000018"].iconAnchor=new GPoint(35, 70); 
icons["030178000018"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001167
icons["030178001167"] = new GIcon(); 
icons["030178001167"].image = "images/thumbs/030178001167.png"; 
icons["030178001167"].iconSize=new GSize(70, 70); 
icons["030178001167"].iconAnchor=new GPoint(35, 70); 
icons["030178001167"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000187
icons["030178000187"] = new GIcon(); 
icons["030178000187"].image = "images/thumbs/030178000187.png"; 
icons["030178000187"].iconSize=new GSize(70, 70); 
icons["030178000187"].iconAnchor=new GPoint(35, 70); 
icons["030178000187"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001100
icons["030178001100"] = new GIcon(); 
icons["030178001100"].image = "images/thumbs/030178001100.png"; 
icons["030178001100"].iconSize=new GSize(70, 70); 
icons["030178001100"].iconAnchor=new GPoint(35, 70); 
icons["030178001100"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000655
icons["030178000655"] = new GIcon(); 
icons["030178000655"].image = "images/thumbs/030178000655.png"; 
icons["030178000655"].iconSize=new GSize(70, 70); 
icons["030178000655"].iconAnchor=new GPoint(35, 70); 
icons["030178000655"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000591
icons["030178000591"] = new GIcon(); 
icons["030178000591"].image = "images/thumbs/030178000591.png"; 
icons["030178000591"].iconSize=new GSize(70, 70); 
icons["030178000591"].iconAnchor=new GPoint(35, 70); 
icons["030178000591"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000601
icons["030178000601"] = new GIcon(); 
icons["030178000601"].image = "images/thumbs/030178000601.png"; 
icons["030178000601"].iconSize=new GSize(70, 70); 
icons["030178000601"].iconAnchor=new GPoint(35, 70); 
icons["030178000601"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000973
icons["030178000973"] = new GIcon(); 
icons["030178000973"].image = "images/thumbs/030178000973.png"; 
icons["030178000973"].iconSize=new GSize(70, 70); 
icons["030178000973"].iconAnchor=new GPoint(35, 70); 
icons["030178000973"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000833
icons["030178000833"] = new GIcon(); 
icons["030178000833"].image = "images/thumbs/030178000833.png"; 
icons["030178000833"].iconSize=new GSize(70, 70); 
icons["030178000833"].iconAnchor=new GPoint(35, 70); 
icons["030178000833"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000806
icons["030178000806"] = new GIcon(); 
icons["030178000806"].image = "images/thumbs/030178000806.png"; 
icons["030178000806"].iconSize=new GSize(70, 70); 
icons["030178000806"].iconAnchor=new GPoint(35, 70); 
icons["030178000806"].infoWindowAnchor=new GPoint(35, 0);


// for 030178000665
icons["030178000665"] = new GIcon(); 
icons["030178000665"].image = "images/thumbs/030178000665.png"; 
icons["030178000665"].iconSize=new GSize(70, 70); 
icons["030178000665"].iconAnchor=new GPoint(35, 70); 
icons["030178000665"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001008
icons["030178001008"] = new GIcon(); 
icons["030178001008"].image = "images/thumbs/030178001008.png"; 
icons["030178001008"].iconSize=new GSize(70, 70); 
icons["030178001008"].iconAnchor=new GPoint(35, 70); 
icons["030178001008"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001033
icons["030178001033"] = new GIcon(); 
icons["030178001033"].image = "images/thumbs/030178001033.png"; 
icons["030178001033"].iconSize=new GSize(70, 70); 
icons["030178001033"].iconAnchor=new GPoint(35, 70); 
icons["030178001033"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001119
icons["030178001119"] = new GIcon(); 
icons["030178001119"].image = "images/thumbs/030178001119.png"; 
icons["030178001119"].iconSize=new GSize(70, 70); 
icons["030178001119"].iconAnchor=new GPoint(35, 70); 
icons["030178001119"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001056
icons["030178001056"] = new GIcon(); 
icons["030178001056"].image = "images/thumbs/030178001056.png"; 
icons["030178001056"].iconSize=new GSize(70, 70); 
icons["030178001056"].iconAnchor=new GPoint(35, 70); 
icons["030178001056"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001831
icons["030178001831"] = new GIcon(); 
icons["030178001831"].image = "images/thumbs/030178001831.png"; 
icons["030178001831"].iconSize=new GSize(70, 70); 
icons["030178001831"].iconAnchor=new GPoint(35, 70); 
icons["030178001831"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000960
icons["030178000960"] = new GIcon(); 
icons["030178000960"].image = "images/thumbs/030178000960.png"; 
icons["030178000960"].iconSize=new GSize(70, 70); 
icons["030178000960"].iconAnchor=new GPoint(35, 70); 
icons["030178000960"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000215
icons["030178000215"] = new GIcon(); 
icons["030178000215"].image = "images/thumbs/030178000215.png"; 
icons["030178000215"].iconSize=new GSize(70, 70); 
icons["030178000215"].iconAnchor=new GPoint(35, 70); 
icons["030178000215"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001867
icons["030178001867"] = new GIcon(); 
icons["030178001867"].image = "images/thumbs/030178001867.png"; 
icons["030178001867"].iconSize=new GSize(70, 70); 
icons["030178001867"].iconAnchor=new GPoint(35, 70); 
icons["030178001867"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001650
icons["030178001650"] = new GIcon(); 
icons["030178001650"].image = "images/thumbs/030178001650.png"; 
icons["030178001650"].iconSize=new GSize(70, 70); 
icons["030178001650"].iconAnchor=new GPoint(35, 70); 
icons["030178001650"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000587
icons["030178000587"] = new GIcon(); 
icons["030178000587"].image = "images/thumbs/030178000587.png"; 
icons["030178000587"].iconSize=new GSize(70, 70); 
icons["030178000587"].iconAnchor=new GPoint(35, 70); 
icons["030178000587"].infoWindowAnchor=new GPoint(35, 0);

// for 030178001672
icons["030178001672"] = new GIcon(); 
icons["030178001672"].image = "images/thumbs/030178001672.png"; 
icons["030178001672"].iconSize=new GSize(70, 70); 
icons["030178001672"].iconAnchor=new GPoint(35, 70); 
icons["030178001672"].infoWindowAnchor=new GPoint(35, 0);

// for 030178000292
icons["030178000292"] = new GIcon(); 
icons["030178000292"].image = "images/thumbs/030178000292.png"; 
icons["030178000292"].iconSize=new GSize(70, 70); 
icons["030178000292"].iconAnchor=new GPoint(35, 70); 
icons["030178000292"].infoWindowAnchor=new GPoint(35, 0);


function get_icon(iconColor) {
   if ((typeof(iconColor)=="undefined") || (iconColor==null)) { 
      // iconColor = "red";
      return;
   }
   if (!icons[iconColor]) {
      icons[iconColor] = new GIcon(icons["red"]);
      icons[iconColor].image = "mapIcons/marker_"+ iconColor +".png";
   } 
   return icons[iconColor];
}
      // ==================================================
      // A function to create a tabbed marker and set up the event window
      // This version accepts a variable number of tabs, passed in the arrays htmls[] and labels[]
      function createTabbedMarker(point,label,tabs,icon) {
        var marker;
        if (icon) {
           marker = new GMarker(point,get_icon(icon));
        } else {
           marker = new GMarker(point);
        }
        var marker_num = gmarkers.length;
        marker.marker_num = marker_num;
        marker.tabs = tabs;
        gmarkers[marker_num] = marker;
        
        GEvent.addListener(gmarkers[marker_num], "click", function() {
          marker.openInfoWindowTabsHtml(gmarkers[marker_num].tabs);
        });
        // add a line to the sidebar html
        side_bar_html += '<li>' + '<a href="javascript:myclick(' + marker_num + ')">' + label + '</a></li>';
        return marker;
      }
      // ==================================================
      


      

function getNodeValue(Element) {
if ((Element.length>0) && Element[0] && Element[0].firstChild && Element[0].firstChild.nodeValue)
   return Element[0].firstChild.nodeValue;
}


      // create the map
      var map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(52.3810, 4.91), 15, G_SATELLITE_MAP);
      var extLargeMapControl = new ExtLargeMapControl();
      map.addControl(extLargeMapControl);
      map.enableScrollWheelZoom();
      G_SATELLITE_MAP.getMinimumResolution = function(){return 13};
      G_SATELLITE_MAP.getMaximumResolution = function(){return 19};
	  




	// Read the data from the associated xml file
   request = GXmlHttp.create();
   // open file and fake a data refresh 
   request.open("GET","data.xml"+"?NoCache="+escape(Date()), true);
   request.onreadystatechange = processTabbedXML;
   request.send(null); 

    }

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

function processTabbedXML() {
   if (request.readyState == 4) {
      if ((request.status != 200) && (request.status != 304)) {
         alert("file not found");
         return;
      }
      // var xmlDoc = request.responseXML;
      var xmlDoc = GXml.parse(request.responseText);
      // obtain the array of markers and loop through it
      var markers = xmlDoc.documentElement.getElementsByTagName("marker");

      // alert("processing "+markers.length+" markers");
      // map.clearOverlays();
      // bug in clearOverlays
      for (var i=0; i<gmarkers.length; i++) {
         map.removeOverlay(gmarkers[i]);
		 
      }
      
      gmarkers = new Array();
      for (var i = 0; i < markers.length; i++) {
         // obtain the attributes of each marker
         var lat = parseFloat(markers[i].getAttribute("lat"));
         var lng = parseFloat(markers[i].getAttribute("lng"));
         var label = markers[i].getAttribute("label");
         var icon = markers[i].getAttribute("icon");

         // alert("point["+i+"] label="+label+":("+lat+", "+lng+")");
         if (isNaN(lat) || isNaN(lng)) {
            alert("bad point "+i);
            continue;
         }
         var point = new GLatLng(lat,lng);
         // get the tab info
         tabInfo = markers[i].getElementsByTagName("tab");
         tabs = new Array();
         if (tabInfo.length > 0) {
            // alert("processing "+tabInfo.length+" tabs");
            for (var j = 0; j < tabInfo.length; j++) {
               var tabLabel = getNodeValue(tabInfo[j].getElementsByTagName("label"));
               var tabHtml = getNodeValue(tabInfo[j].getElementsByTagName("contents"));
               // alert("point["+i+"] tab["+j+"] label="+tabLabel+", contents="+tabHtml);
               if ((j==0) && (tabInfo.length > 2)){ //  adjust the width so that the info window is large enough for this many tabs
                  tabHtml = '<div>' + tabHtml + '</div>';
               }
               tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
            }
         } else { 
            // alert("no tabs point "+i);
            var tabLabel = "Nothing";
            var tabHtml = markers[i].getAttribute("html");
            tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
         }      

         // create the marker
         var marker = createTabbedMarker(point,label,tabs, icon);
         bounds.extend(point);

         map.addOverlay(marker);
      }
      map.centerAndZoomOnBounds(bounds);

      // put the assembled sidebar_html contents into the sidebar div
      document.getElementById("side_bar").innerHTML = side_bar_html;
      side_bar_html = "";
   }
}
} // end of onLoad function

