

//<![CDATA[

if (GBrowserIsCompatible()) {

  // This function picks up the click and opens the corresponding info window
  function myclick(i) {
    gmarkers[i].openInfoWindowHtml('<div style="white-space:nowrap;">'+gmarkers[i].my_html+'</div>');
  }


  // create the map
  var map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
//  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(20, 25), 3, G_HYBRID_MAP);
  
  // array to hold copies of the markers 
  // we cant scan map.overlays[] because the order of the entries changes
  var gmarkers = [];
  

  // Read the data from example.xml
  var request = GXmlHttp.create();
  request.open("GET", "googlepoints1.xml", true);
  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      var xmlDoc = request.responseXML;

      // 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 GPoint(lng,lat);
        var html = markers[i].getAttribute("html");
        var label = markers[i].getAttribute("label");
        // create the marker
        var marker = new GMarker(point);
        marker.my_html = html;
        marker.my_name = label;
        map.addOverlay(marker);
        gmarkers.push(marker);
      }

      /*
      // this variable will collect the html which will eventually be placed in the sidebar
      var sidebar_html = "";
        
      // scan through the gmarkers[] array assembling the sidebar html
      for (var i=0; i < gmarkers.length; i++) {
        if (gmarkers[i].my_name) {
           sidebar_html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].my_name + '</a><br>';
        }
      }        
      
      // put the assembled sidebar_html contents into the sidebar div
      //////////////// DISABLED FOR NOW document.getElementById("sidebar").innerHTML = sidebar_html;
      */

    }
  }
  request.send(null);
  
  GEvent.addListener(map, "click", 
    function(overlay, point) {
      if (overlay) {
        if (overlay.my_html) {
          overlay.openInfoWindowHtml('<div style="white-space:nowrap;">'+overlay.my_html+'</div>');
        }
      }
    }
  );      
}
//]]>
  
