// JavaScript Document
<!-- Script to create Google map -->
//<![CDATA[

    if (GBrowserIsCompatible()) {
      // this variable will collect the html which will eventualkly be placed in the side_bar
      var side_bar_html1 = "";
	  var side_bar_html2 = "";

      // arrays to hold copies of the markers and html used by the side_bar
      // because the function closure trick doesnt work there
      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 = [];
      
      // === Create an associative array of GIcons() ===
      var gicons = [];
      gicons["icon1"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_1.png");
      gicons["icon2"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_2.png");
      gicons["icon3"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_3.png");
	  gicons["icon4"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_4.png");
	  gicons["icon5"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_5.png");
	  gicons["icon6"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_6.png");
	  gicons["icon7"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_7.png");
	  gicons["icon8"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_8.png");
	  gicons["icon9"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_9.png");
	  gicons["icon10"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_10.png");
	  gicons["icon11"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_11.png");
	  gicons["icon12"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_12.png");
	  gicons["icon13"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_13.png");
	  gicons["icon14"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_14.png");
	  gicons["icon15"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_15.png");
	  gicons["icon16"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_16.png");
	  gicons["icon17"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_17.png");
	  gicons["icon18"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_18.png");
	  gicons["icon19"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_19.png");
	  gicons["icon20"] = new GIcon(G_DEFAULT_ICON, "../map_icons/apartment_20.png");
	

      // A function to create the marker and set up the event window
      function createMarker(point,name,html,icontype) {
        var marker = new GMarker(point, gicons[icontype]);
		
        // The info window version with the "to here" form open
        to_htmls[i] = html + '<br>Directions: <b>To here</b> - <a href="javascript:fromhere(' + i + ')">From here</a>' +
           '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
                  // "(" + name + ")" + 
           '"/><br>&nbsp;';
        // The info window version with the "to here" form open
        from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')">To here</a> - <b>From here</b>' +
           '<br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
                  // "(" + name + ")" + 
           '"/><br>&nbsp;';
        // The inactive version of the direction info
        html = html + '<br>Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a><br>&nbsp;';
		
        GEvent.addListener(marker, "mouseover", function() {
          marker.openInfoWindowHtml(html);
		  if(map.getZoom()<10){
		  	map.setZoom(10);
		  }
        });
		
		map.enableDoubleClickZoom();
		
		<!--GEvent.addListener(map, "dblclick", function() {map.setZoom(10);});-->
		
		
        // 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
		
		// The number 6 below represents half the number of entries into the side_bar
		if(i<5){
        side_bar_html1 += '<font size="2"><a href="javascript:mymouseover(' + i + ')" onmouseover="mymouseover('+i+')">' + name + '</a></font><br>';
		}
		else{
		side_bar_html2 += '<font size="2"><a href="javascript:mymouseover(' + i + ')" onmouseover="mymouseover('+i+')">' + name + '</a></font><br>';
		}
        i++;
        return marker;
      }

	  
	  
	  
      // This function picks up the mouseover and opens the corresponding info window
      function mymouseover(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
		  if(map.getZoom()<10){
		  	map.setZoom(10);
		  }
      }

      // 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 GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(0,0),0);
	  map.enableGoogleBar();


      // Read the data from example5.xml
	  var bounds = new GLatLngBounds();
      var request = GXmlHttp.create();
	  
	  //Change path to url to test outside of server
      request.open("GET", "../xml/dfw_apts.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 GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            // === read the icontype attribute ===
            var icontype = markers[i].getAttribute("icontype");
            // === create the marker, passing the icontype string ===
            var marker = createMarker(point,label,html,icontype);
            map.addOverlay(marker);
			bounds.extend(point);
          }
          // put the assembled side_bar_html contents into the side_bar div
          document.getElementById("side_bar1").innerHTML = side_bar_html1;
		  document.getElementById("side_bar2").innerHTML = side_bar_html2;
		  
		  // ===== determine the zoom level from the bounds =====
          map.setZoom(map.getBoundsZoomLevel(bounds));

          // ===== determine the centre from the bounds ======
          map.setCenter(bounds.getCenter());
        }
      }
      request.send(null);
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://www.econym.demon.co.uk/googlemaps/

    //]]>