// Southern Utah Area Golf Courses, including the Red Rock Golf Trail Google Map Code. //
// Copyright 2006 Hurricane Geographics (435)635-3051.                                //
// Author: Joe Rhodes, jerhodes@charter.net                                          //

    //<![CDATA[

    if (GBrowserIsCompatible()) 
    {
      // ========= define array to hold copies of the map markers for later functions =========== //
         var gmarkers = [];

      // ========= define array to hold info bubble html (htmls) =========== //
         var info_html = [];

      // ========= Index variable =========== //
         var i = 0;

      // ========= variables for map extents =========== //
         var mapcenlat = 37.102836499286454;
         var mapcenlon = -113.51829528808594;
         var mapzoom = 11;

      // ========= Create an associative array of GIcons() =========== //
         var gicons = [];

	 var iconfa = new GIcon();
	 iconfa.image = "fa.jpg";
	 iconfa.iconSize = new GSize(148, 24);
	 iconfa.iconAnchor = new GPoint(74, 12);
	 iconfa.infoWindowAnchor = new GPoint(74, 12);
         gicons["fa"] = iconfa;

	 var icongnp = new GIcon();
	 icongnp.image = "gnp.jpg";
	 icongnp.iconSize = new GSize(148, 24);
	 icongnp.iconAnchor = new GPoint(74, 12);
	 icongnp.infoWindowAnchor = new GPoint(74, 12);
         gicons["gnp"] = icongnp;

	 var iconnp = new GIcon();
	 iconnp.image = "np.jpg";
	 iconnp.iconSize = new GSize(148, 24);
	 iconnp.iconAnchor = new GPoint(74, 12);
	 iconnp.infoWindowAnchor = new GPoint(74, 12);
         gicons["np"] = iconnp;

	 var iconsc = new GIcon();
	 iconsc.image = "sc.jpg";
	 iconsc.iconSize = new GSize(148, 24);
	 iconsc.iconAnchor = new GPoint(74, 12);
	 iconsc.infoWindowAnchor = new GPoint(74, 12);
         gicons["sc"] = iconsc;

	 var iconwcs = new GIcon();
	 iconwcs.image = "wcs.jpg";
	 iconwcs.iconSize = new GSize(148, 24);
	 iconwcs.iconAnchor = new GPoint(74, 12);
	 iconwcs.infoWindowAnchor = new GPoint(74, 12);
         gicons["wcs"] = iconwcs;

	 var iconwcn = new GIcon();
	 iconwcn.image = "wcn.jpg";
	 iconwcn.iconSize = new GSize(148, 24);
	 iconwcn.iconAnchor = new GPoint(74, 12);
	 iconwcn.infoWindowAnchor = new GPoint(74, 12);
         gicons["wcn"] = iconwcn;

      //** function to create the markers, set up the marker listener, and the side bar menu div elements. **//
           function createMarker(point,html,img) 
	   {
              html = '<div class="mkinfo">' + html + '</div>';
              var marker = new GMarker(point, gicons[img]);
              GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
           // save the info for markers and info windows in arrays
              gmarkers[i] = marker;
              info_html[i] = html;
              i++;
              return marker;
           }
	   // END FUNCTION //

      //*** This function recenters the map. ***//
          function recenter() 
          {
             map.closeInfoWindow()
             map.setCenter(new GLatLng(mapcenlat, mapcenlon), mapzoom);
          }
	  // END FUNCTION //

      //*******************************  BEGIN MAIN ***********************************//
      // ========= create the map =========== //
         var map = new GMap2(document.getElementById("map"));
         map.addControl(new GLargeMapControl());
         map.addControl(new GMapTypeControl());
         map.setCenter(new GLatLng(mapcenlat, mapcenlon), mapzoom);
      // ================================================ //
      
      // ========= Read the data from XML file and create markers =========== //
         var request = GXmlHttp.create();
         request.open("GET", "wacotransdata.xml", true);
         request.onreadystatechange = function() 
         {
            if (request.readyState == 4) 
            {
               var xmlDoc = request.responseXML;
               var markers = xmlDoc.documentElement.getElementsByTagName("marker");

            // ========= loop through the array of markers =========== ///
               for (var i = 0; i < markers.length; i++) 
               {
               // get marker attributes //
                  var lat = parseFloat(markers[i].getAttribute("lat"));
                  var lng = parseFloat(markers[i].getAttribute("lng"));
                  var point = new GPoint(lng,lat);
                  var name = markers[i].getAttribute("name");
  	          var img = markers[i].getAttribute("img");
                  var desc = markers[i].getAttribute("desc");
                  var contact = "<p><em>Contacts: </em><br>" + markers[i].getAttribute("contact") + "</p>";
                  var html = "<b>" + name + "</b></br>" + "<p><em>Project Description</em><br>" + desc + "</p>" + contact;
               // create the marker //
                  var marker = createMarker(point,html,img);
                  map.addOverlay(marker);
               }
               // END FOR LOOP //

            // ========= process the polylines =========== //
               var lines = xmlDoc.documentElement.getElementsByTagName("line");
            // read coordinates of each line in the file
               for (var a = 0; a < lines.length; a++) 
               {
               // get any line attributes
                  var color = lines[a].getAttribute("color");
                  var width  = parseFloat(lines[a].getAttribute("width"));
               // read each point on that line
                  var points = lines[a].getElementsByTagName("point");
                  var pts = [];
                  for (var i = 0; i < points.length; i++) 
                    {
                       pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
                                     parseFloat(points[i].getAttribute("lng")));
                    }
                    // END FOR LOOP //
                 map.addOverlay(new GPolyline(pts,color,width));
               }
               // END FOR LOOP //
           // ================================================ //
            } // END IF //

         } // END REQUEST //
         request.send(null);
    }
    else 
      {
         alert("Sorry, Google Maps API is not compatible with this browser");
      }
    // END IF //

    //]]>


