//
//                                            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
    //
    function MasterMap() {
        this.map = new GMap(document.getElementById("map"));
        (this.map).addControl(new GSmallZoomControl());
        (this.map).centerAndZoom(new GPoint(city[CrescentCity][0],city[CrescentCity][1]), 4);
    }

    //
    //    MasterMap.Reposition
    //
    //    Reposition the map to the center of a city.
    //
    MasterMap.prototype.Reposition = function(index) {  
         var point = new GPoint(city[index][0],city[index][1]) ;        
         (this.map).recenterOrPanToLatLng(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 GPoint(propertyList[i].longitude,propertyList[i].latitude) ;    
                    var marker = createMarker(point, propertyList[i]);
                    (this.map).addOverlay(marker);
                }
            }
        }        
    }
