//<![CDATA[

    var map = null;
    var geocoder = null;
    var bounds = null;
    
    function GLoad() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(37.4419, -122.1419), 3);
        geocoder = new GClientGeocoder();
	bounds = new GLatLngBounds();
	//mgr = new GMarkerManager(map);
	markers = [];
	// If the drawPoints function has been defined by the page, call it:
	if(typeof self.drawPoints !="undefined") { drawPoints(); }
	//mgr.addMarkers(markers, 0);
	map.setCenter(bounds.getCenter());
	map.setZoom(map.getBoundsZoomLevel(bounds));
	//mgr.refresh();
      	  //var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
      	  //var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
      	  //map.setCenter(new GLatLng(clat,clng));
	 
      }
    }

    function showAddress(address, displayText) {
      var point = null;
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
             // map.setCenter(point, 13);
              var marker = new GMarker(point);
	      GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(displayText); });
              map.addOverlay(marker);
		bounds.extend(point);
		//alert("setting bounds " + point.lat() + ', ' + point.lng())
              //marker.openInfoWindowHtml(address);
            }
          }
        );
      }
     // return bounds;
    }
    
    function addPoint(lat, lng, displayText) {
	    point = new GLatLng(lat, lng, true);
            var marker = new GMarker(point);
	    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(displayText); });
	    bounds.extend(point);
	    markers.push(marker);
    }


    function showPoint(lat, lng, displayText, icon) {
	    if (typeof icon == "undefined") {
		    icon = G_DEFAULT_ICON;
	    }
	    point = new GLatLng(lat, lng, true);
            var marker = new GMarker(point, icon);
	    if (displayText != '') 
	    {
		    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(displayText); });
	    }
            map.addOverlay(marker);
	    bounds.extend(point);
    }
 
	function addListener(element, event, listener, bubble) {
	  if(element.addEventListener) {
	    if(typeof(bubble) == "undefined") bubble = false;
	    element.addEventListener(event, listener, bubble);
	  } else if(this.attachEvent) {
	    element.attachEvent("on" + event, listener);
	  }
	}
	
	if(typeof self.GUnload !="undefined") {
		addListener(this, "load", function() { GLoad(); });
		addListener(document, "load", function() { GLoad(); });
		addListener(this, "unload", function() { GUnload(); });
		addListener(document, "unload", function() { GUnload(); });
	}

    
 //]]>
