    //<![CDATA[


var map;
var markerMgr;

    var neighborhoodMarkers = [
      {"name":"Castro",              "lat":37.76257271890943, "lng":-122.43503093719482},
      {"name":"SOMA",       "lat":37.779398571318765, "lng":-122.39760875701904},
      {"name":"North Beach",  "lat":37.80001858607365, "lng":-122.40979671478271},
    ]

/* LOAD FUNCTIONS */
function load() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map")); 

  
    mapSize = map.getSize();
    document.getElementById('maploading').style.height = mapSize.height + "px";
    document.getElementById('maploading').style.width = mapSize.width + "px";


    map.enableScrollWheelZoom();
    map.addControl(new GLargeMapControl());
    map.addControl(new GOverviewMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(37.776472979858326, -122.43453741073608), 9);  
    southWest =  map.getBounds().getSouthWest() ;
    northEast =  map.getBounds().getNorthEast() ;
    boundSpan = map.getBounds().toSpan();
    markerSouthWestLat = southWest.lat() - boundSpan.lat();
    markerSouthWestLng = southWest.lng() + boundSpan.lng();
    markerNorthEastLat = northEast.lat() + boundSpan.lat();
    markerNorthEastLng = northEast.lng() - boundSpan.lng();

    oldCenter = map.getBounds();
    document.getElementById('maploading').style.visibility = "visible";

    GEvent.addListener(map, "zoomend", function() { 
      update();
    });

    GEvent.addListener(map, "dragend", function() { 
      foo1 = new GLatLng(oldCenter.getSouthWest().lat() + boundSpan.lat()/2 , oldCenter.getSouthWest().lng() - boundSpan.lng()/2);
      foo2 = new GLatLng(oldCenter.getNorthEast().lat() - boundSpan.lat()/2 ,oldCenter.getNorthEast().lng() + boundSpan.lng()/2);
      foo = new GLatLngBounds(foo1, foo2);
      newCenter = map.getBounds();

      if ( newCenter.intersects(foo) ) {
      } else {
        update();
      }
    }); 

    GEvent.addListener(map, "moveend", function() { 
      newCenter = map.getBounds();
      if ( newCenter.intersects(oldCenter) ) {
      } else {
        update();
      }
    }); 

  }


  markerImageRestaurants = new Image();
  markerImageRestaurants.src = "\/petfriendly\/googlemapimages\/diningmarker.png";

  markerImageRestaurantsShadow = new Image();
  markerImageRestaurantsShadow.src = "\/petfriendly\/googlemapimages\/diningmarker_shadow.png";

  markerImageShops = new Image();
  markerImageShops.src = "\/petfriendly\/googlemapimages\/shoppingmarker.png";

  markerImageShopsShadow = new Image(); 
  markerImageShopsShadow.src = "\/petfriendly\/googlemapimages\/shoppingmarker_shadow.png";

}


/* CREATE MARKERS FOR DISPLAY */
function createMarker(locationid,point,name,address,address2,city,state,zip,web_url,phone,email,logo,businesstype,image) {

  var icon = new GIcon();

  if(businesstype == 'Restaurant'){
    icon.image = "/petfriendly/googlemapimages/diningmarker.png";
    icon.shadow = "/petfriendly/googlemapimages/diningmarker_shadow.png";
  } else {
    icon.image = "/petfriendly/googlemapimages/shoppingmarker.png";
    icon.shadow = "/petfriendly/googlemapimages/shoppingmarker_shadow.png";
  }

  icon.iconSize = new GSize(31, 53);
  icon.shadowSize = new GSize(63, 53);
  icon.iconAnchor = new GPoint(14, 49);
  icon.infoWindowAnchor = new GPoint(15, 1);


  var marker = new GMarker(point, icon);

  GEvent.addListener(marker, "click", function() {
    var infoTabs = [
      new GInfoWindowTab("Location", "<div id='maplocationdisplay'><img src=/petfriendly/googlemapimages/maploading_small.gif></div>"),
      new GInfoWindowTab("Info", "<div id='maplocationinfo'><img src=/petfriendly/googlemapimages/maploading_small.gif></div>"),      
      new GInfoWindowTab("Photos", "<div id='maplocationphotos'><img src=/petfriendly/googlemapimages/maploading_small.gif></div>")
    ];

    mapLocationDisplay(locationid); 
    mapLocationInfo(locationid);
    mapLocationPhotos(locationid);

    marker.openInfoWindowTabsHtml(infoTabs);

  });

  return marker;
}



function update() {
  oldCenter = map.getBounds();

  // ===== Start with an empty GLatLngBounds object =====     
  var bounds = new GLatLngBounds();

  map.clearOverlays();

  southWest =  map.getBounds().getSouthWest() ; 
  northEast =  map.getBounds().getNorthEast() ;
  boundSpan = map.getBounds().toSpan();
  markerSouthWestLat = southWest.lat() - boundSpan.lat();
  markerSouthWestLng = southWest.lng() + boundSpan.lng();
  markerNorthEastLat = northEast.lat() + boundSpan.lat();
  markerNorthEastLng = northEast.lng() - boundSpan.lng();

  var heaters = document.getElementById('heaters');

  if (heaters.checked) {
    var hasheaters = "yes";
  } else {
    var hasheaters = "";
  }

  var tablestyles = document.getElementsByName('tablestyle');
  var tablestylescount = document.getElementsByName('tablestyle').length;
  var checkedtablestyles = new Array()

  for(i = 0; i<tablestylescount; i++){
    if(tablestyles[i].checked) {
      checkedtablestyles.push(tablestyles[i].value); 
    }
  }

  var neighborhoods = document.getElementsByName('neighborhood');
  var neighborhoodcount = document.getElementsByName('neighborhood').length;
  var checkedneighborhoods = new Array()

  for(i = 0; i<neighborhoodcount; i++){
    if(neighborhoods[i].checked) {
      checkedneighborhoods.push(neighborhoods[i].value); 
    }
  }

  var cuisine = document.getElementsByName('cuisine_type');
  var cuisinecount = document.getElementsByName('cuisine_type').length;
  var checkedcuisine = new Array()

  for(i = 0; i<cuisinecount; i++){
    if(cuisine[i].checked) {
      checkedcuisine.push(cuisine[i].value); 
    }
  }

  var business_type = document.getElementsByName('business_type'); 
  var business_typecount = business_type.length;
  var checkedbusinesstypes = new Array()

  for(i = 0; i<business_typecount; i++){
    if(business_type[i].checked) {
      checkedbusinesstypes.push(business_type[i].value); 
    }
  }

  var request = GXmlHttp.create();
  request.open("GET", "http://www.diningwithsophie.com/cgi-bin/petfriendly/locations.xml?markerSouthWestLat=" + markerSouthWestLat + "&markerSouthWestLng=" + markerSouthWestLng + "&markerNorthEastLat=" + markerNorthEastLat +  "&markerNorthEastLng=" + markerNorthEastLng + "&neighborhood=" + checkedneighborhoods.join("|") + "&cuisine=" + checkedcuisine.join("|") + "&business_type=" + checkedbusinesstypes.join("|") + "&tablestyle=" + checkedtablestyles.join("|") + "&heaters=" + hasheaters , true);
  request.onreadystatechange = function() {
      
    if (request.readyState == 3) {
      document.getElementById('maploading').style.visibility = "visible";
    }

    if (request.readyState == 4) {
      document.getElementById('maploading').style.visibility = "hidden";
      var xmlDoc = request.responseXML;
      var points = xmlDoc.documentElement.getElementsByTagName("marker");
      for (var i = 0; i < points.length; i++) {
        var point = new GLatLng(parseFloat(points[i].getAttribute("latitude")),parseFloat(points[i].getAttribute("longitude")));
        var locationid = points[i].getAttribute("locationid");
        var name = points[i].getAttribute("name");
        var address = points[i].getAttribute("address");
        var address2 = points[i].getAttribute("address2");
        var city = points[i].getAttribute("city");
        var state = points[i].getAttribute("state");
        var zip = points[i].getAttribute("zip");
        var web_url = points[i].getAttribute("web_url");
        var phone = points[i].getAttribute("phone");
        var email = points[i].getAttribute("email");
        var logo = points[i].getAttribute("logo");
        var image = points[i].getAttribute("image");
        var businesstype = points[i].getAttribute("businesstype");
        var marker = createMarker(locationid,point,name,address,address2,city,state,zip,web_url,phone,email,logo,businesstype,image);
        map.addOverlay(marker);
        bounds.extend(point);
      }

      // ===== determine the zoom level from the bounds =====
      //       map.setZoom(map.getBoundsZoomLevel(bounds));

      // ===== determine the centre from the bounds ======
      var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
      var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
      //     map.setCenter(new GLatLng(clat,clng));
    }
  }
  request.send(null);
}




//]]>

