//<![CDATA[

  var details_html = "";
  var gmarkers = [];
  var bubbles = [];
  var i = 0;
  var map;

  function MAPload2(mlat, mlon, mzoom)
  {
    if (GBrowserIsCompatible()) 
    {
      map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());

      // initialize to center of the continental US (may use function later to be more relevant)
      map.setCenter(new GLatLng( mlat, mlon), mzoom);
      document.getElementById("statusbar").innerHTML = "Select a category to map!";
    }
  }

  function MAPload()
  {
    if (GBrowserIsCompatible()) 
    {
      map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());

      // initialize to center of the continental US (may use function later to be more relevant)
      map.setCenter(new GLatLng( 38.799999,-97.769997), 2);
      document.getElementById("statusbar").innerHTML = "Select a category to map!";
    }
  }

  function createMarker(point,title,teaser,bubble,actname) 
  {
    var bubble2 = title + '<br />' + bubble;
    var marker = new GMarker(point, {title:actname});
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(bubble2);});
    gmarkers[i] = marker;
    bubbles[i] = bubble2;
    details_html += "<li>" + title + " <a href='javascript:myclick(" + i + ")'>(find on map)</a> " + teaser + "</li>";
    i++;
    return marker;
  }

  function myclick(i) 
  {
    gmarkers[i].openInfoWindowHtml(bubbles[i]);
    map.setCenter(gmarkers[i].getPoint());
  }

  function readMap(url,category) 
  {
    if (GBrowserIsCompatible()) 
    {
      document.getElementById("statusbar").innerHTML = "Mapping data, please wait..";
      var request = GXmlHttp.create();
      request.open("GET", url, true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          // repeat status in case xml is cached - map still takes time
          document.getElementById("statusbar").innerHTML = "Mapping data, please wait..";
          var xmlDoc = request.responseXML;
          // obtain the array of markers and loop through it
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");        
          // hide the info window, otherwise it still stays open where the removed marker used to be
          map.getInfoWindow().hide();
           
          map.clearOverlays();
            
          // empty the array
          gmarkers = [];

          // set map center and zoom level
          //map.setCenter(new GLatLng( 34.562351, -111.852791), 6);

          var bounds = new GLatLngBounds();       

          // reset the details area
          details_html ="<center><h2 id='statusbar'>Now showing: " + category + "!</h2></center>"
          details_html +="<hr /><h3>" + category + "</h3><ul class='actlist2'>";                
          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);
            bounds.extend(point);
            var title = markers[i].getAttribute("title");
            var teaser = markers[i].getAttribute("teaser");
            var bubble = markers[i].getAttribute("bubble");
            var actname = markers[i].getAttribute("actname");
            // create the marker
            var marker = createMarker(point,title,teaser,bubble,actname);
            map.addOverlay(marker);
          }
 
          // set zoom to capture all markers
          var myZoom = 9;
          var calcZoom = map.getBoundsZoomLevel(bounds); // could use -1 if pins at edges
          if (calcZoom <= myZoom) { myZoom = calcZoom; }
          map.setZoom(myZoom);
          var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
          var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
          map.setCenter(new GLatLng(clat,clng));

          // put the assembled details_html contents into the mapgroup div
          details_html += "</ul>";
          document.getElementById("mapgroup").innerHTML = details_html;
        }
      }
      request.send(null);
    }
  }

  function MAPsize() 
  { 
    if (GBrowserIsCompatible()) 
    {
    map.checkResize(); 
    }
  }         


//  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/


//]]>