//
//                                            MasterMap.js
//
//
//   This file contains utilities used in the master map of each page.  
//   
//
//  

     //
     //    createMarker
     //
     //   Create a marker and associate it to a specific property.
     //
    function createMarker(point, property) {

        var marker = new GMarker(point);                                                         
        var html = property.infoBlock() ;

        GEvent.addListener(marker, "click", function() { 
            marker.openInfoWindowHtml(html) ;
         });

        return marker;
    }
    
    // 
    //    MasterMap
    //
    //    Construct a map centered on Crescent City
    //
    var the_geocoder ;
    function MasterMap() {
      if (GBrowserIsCompatible()) {
        this.map = new GMap2(document.getElementById("map"));
        this.map.setCenter(new GLatLng(city[CrescentCity][1], city[CrescentCity][0]), 13);
        (this.map).addControl(new GSmallMapControl());
        the_geocoder = new GClientGeocoder() ;
      } else {
          alert("Sorry, Your Browser is not compatible with GOOGLE MAP.  I can not show you the map.") ;
      }   
    }

    //
    //    addAddressToMap
    //
    //    This callback provides a method for responding to Google's identification of the longitude and latitude of an address.
    //    It will place the address on the map.
    //
function addAddressToMap(response) {
    alert("response") ;
    if (!response || response.Status.code != 200) {
        alert("\"" + address + "\" not found");
    } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
        marker = new GMarker(point);
        the_map.addOverlay(marker);
        marker.openInfoWindowHtml(place.address + '<br>' + place.Point.coordinates[1] + ":" + place.Point.coordinates[0]);
    }
}

    //  
    //   markLocation
    //
    //    This provides a method for requesting the retrieval of a longitude and latitude.
    //
function markLocation(address) {
    alert("getting location"+address)
    the_geocoder.getLocations(address, addAddressToMap) ;

}

    //
    //    MasterMap.Reposition
    //
    //    Reposition the map to the center of a city.
    //
    MasterMap.prototype.Reposition = function(index) {  
         var point = new GLatLng(city[index][1],city[index][0]) ;        
         (this.map).setCenter(point) ;
    }
    
    //
    //    MasterMap.addOverlay
    //
    //    Add a marker to the MasterMap
    //
    MasterMap.prototype.addOverlay = function(marker) {
        (this.map).addOverlay(marker) ;
    }
    
    function mapSet(a_map, index) {
          a_map.Reposition(index) ;
    }

    MasterMap.prototype.updateOverlay = function() {
	var price    = new String() ;
        var tmp      = new String() ;
	    var the_min  = new String() ;
        var the_max  = new String() ;
        (this.map).clearOverlays() ;

        for (var i = 1; i < propertyList.length ; i++) {
            tmp = propertyList[i].price ;
            price   = tmp.replace(/,/g, "") ;
            if (isCategory(propertyList[i]) == true) {
                tmp     = Value[filter.minimum.selectedIndex] + "000" ;
		the_min = tmp.replace(/,/g,"") ;
                tmp     = Value[filter.maximum.selectedIndex] + "000" ;
		the_max = tmp.replace(/,/g,"") ;
                if ((parseInt(the_min) <= parseInt(price) ) && (parseInt(price) <= parseInt(the_max)))  {  
                    var point = new GLatLng(propertyList[i].latitude,propertyList[i].longitude) ;    
                    var marker = createMarker(point, propertyList[i]);
                    (this.map).addOverlay(marker);
                    
                }
            }
        } 
        
        // markLocation("1715 Del Mar Road, Crescent City, CA") ;       
 
    }
