$(function() {
  if (GBrowserIsCompatible()) {
  
  	// Initialize the map
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.7, -122.3), 9);
    map.setUIToDefault();
    
    // Set up address geocoding
    var geocoder = new GClientGeocoder();
	function showMarker(club) {
	  var html = '<h2>Club One at ' + club.getAttribute("name") + '</a></h2><p>' + club.getAttribute("address") + '<br />' + club.getAttribute("city") + '</p><p><a href="/?action=cl1pub_club_home&template=clubone_new/cl1pub_club_home.htm7&ClubID=' + club.getAttribute("id") + '">More info &rarr;</a></p>';
	  geocoder.getLatLng(
	    club.getAttribute("address") + ", " + club.getAttribute("city") + ", " + club.getAttribute("state"),
	    function(point) {
	      if (point) {
	        var marker = new GMarker(point);
	        map.addOverlay(marker);
	        GEvent.addListener(marker, "click", function() {
	         marker.openInfoWindowHtml(html);
            });
	      }
	    }
	  );
	}
    
    // Parse the XML file
    GDownloadUrl("/?action=cl1pub_club_list&template=clubs_list_xml.htm7&Regions=1,3&q=2", function(data, responseCode) {
	  var xml = GXml.parse(data);
	  var clubs = xml.documentElement.getElementsByTagName("club");
	  for (var i = 0; i < clubs.length; i++) {
	  	showMarker(clubs[i]);
	  }
	});
    
    
  }
});

$(window).unload(function(){ 
	GUnload(); 
});
