/*
	ClusterMarker Version 1.3.0
	
	A marker manager for the Google Maps API
	http://googlemapsapi.martinpearman.co.uk/clustermarker
	
	Copyright Martin Pearman 2008
	Last updated 5th March 2008

	This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
	
	Changes By Igor Aloise Mordashev
	
	var minMarkersPerCluster = 0;	The minimum amount of markers to cluster.
	
	+ Interoperability with Google MarkerManager 
	
*/

function ClusterMarker($map, $options){
	this._map=$map;
	this._mapMarkers=[];
	this._iconBounds=[];
	this._clusterMarkers=[];
	this._eventListeners=[];
	this.minMarkersPerCluster = 1;
	if(typeof($options)==='undefined'){
		$options={};
	}
	this.borderPadding=($options.borderPadding)?$options.borderPadding:256;
	this.clusteringEnabled=($options.clusteringEnabled===false)?false:true;
	if($options.clusterMarkerClick){
		this.clusterMarkerClick=$options.clusterMarkerClick;
	}
	if($options.clusterMarkerIcon){
		this.clusterMarkerIcon=$options.clusterMarkerIcon;
	}else{
		this.clusterMarkerIcon=new GIcon();
		this.clusterMarkerIcon.image='http://maps.google.com/mapfiles/arrow.png';
		this.clusterMarkerIcon.iconSize=new GSize(39, 34);
		this.clusterMarkerIcon.iconAnchor=new GPoint(9, 31);
		this.clusterMarkerIcon.infoWindowAnchor=new GPoint(9, 31);
		this.clusterMarkerIcon.shadow='http://www.google.com/intl/en_us/mapfiles/arrowshadow.png';
		this.clusterMarkerIcon.shadowSize=new GSize(39, 34);
	}
	this.clusterMarkerTitle=($options.clusterMarkerTitle)?$options.clusterMarkerTitle:'Click to zoom in and see %count markers';
	if($options.fitMapMaxZoom){
		this.fitMapMaxZoom=$options.fitMapMaxZoom;
	}
	this.intersectPadding=($options.intersectPadding)?$options.intersectPadding:0;
	if($options.markers){
		this.addMarkers($options.markers);
	}
	
	if($options.minMarkersPerCluster)
	{
		this.minMarkersPerCluster = $options.minMarkersPerCluster;
	}
	
	GEvent.bind(this._map, 'moveend', this, this._moveEnd);
	GEvent.bind(this._map, 'zoomend', this, this._zoomEnd);
	GEvent.bind(this._map, 'maptypechanged', this, this._mapTypeChanged);
}

ClusterMarker.prototype.addMarkers=function($markers){
	var i;
	if(!$markers[0]){
		//	assume $markers is an associative array and convert to a numerically indexed array
		var $numArray=[];
		for(i in $markers){
			$numArray.push($markers[i]);
		}
		$markers=$numArray;
	}
	for(i=$markers.length-1; i>=0; i--){
		$markers[i]._isVisible=false;
		$markers[i]._isActive=false;
		$markers[i]._makeVisible=false;
	}
	this._mapMarkers=this._mapMarkers.concat($markers);
};

ClusterMarker.prototype.addMarker = function( marker )
{
	this.addMarkers([ marker ]);
}

ClusterMarker.prototype._clusterMarker=function($clusterGroupIndexes){
	function $newClusterMarker($location, $icon, $title){
		return new GMarker($location, {icon:$icon, title:$title});
	}
	var $clusterGroupBounds=new GLatLngBounds(), i, $clusterMarker, $clusteredMarkers=[], $marker, $this=this;
	for(i=$clusterGroupIndexes.length-1; i>=0; i--){
		$marker=this._mapMarkers[$clusterGroupIndexes[i]];
		$marker.index=$clusterGroupIndexes[i];
		$clusterGroupBounds.extend($marker.getLatLng());
		$clusteredMarkers.push($marker);
	}
	$clusterMarker=$newClusterMarker($clusterGroupBounds.getCenter(), this.clusterMarkerIcon, this.clusterMarkerTitle.replace(/%count/gi, $clusterGroupIndexes.length));
	$clusterMarker.clusterGroupBounds=$clusterGroupBounds;	//	only req'd for default cluster marker click action
	this._eventListeners.push(GEvent.addListener($clusterMarker, 'click', function(){
		$this.clusterMarkerClick({clusterMarker:$clusterMarker, clusteredMarkers:$clusteredMarkers });
	}));
	return $clusterMarker;
};


ClusterMarker.prototype.defaultMarkerClick = ClusterMarker.prototype.clusterMarkerClick = function($args){
	this._map.setCenter($args.clusterMarker.getLatLng(), this._map.getBoundsZoomLevel($args.clusterMarker.clusterGroupBounds));
};

ClusterMarker.prototype._filterActiveMapMarkers=function(){
	var $borderPadding=this.borderPadding, $mapZoomLevel=this._map.getZoom(), $mapProjection=this._map.getCurrentMapType().getProjection(), $mapPointSw, $activeAreaPointSw, $activeAreaLatLngSw, $mapPointNe, $activeAreaPointNe, $activeAreaLatLngNe, $activeAreaBounds=this._map.getBounds(), i, $marker, $uncachedIconBoundsIndexes=[], $oldState;
	if($borderPadding){
		$mapPointSw=$mapProjection.fromLatLngToPixel($activeAreaBounds.getSouthWest(), $mapZoomLevel);
		$activeAreaPointSw=new GPoint($mapPointSw.x-$borderPadding, $mapPointSw.y+$borderPadding);
		$activeAreaLatLngSw=$mapProjection.fromPixelToLatLng($activeAreaPointSw, $mapZoomLevel);
		$mapPointNe=$mapProjection.fromLatLngToPixel($activeAreaBounds.getNorthEast(), $mapZoomLevel);
		$activeAreaPointNe=new GPoint($mapPointNe.x+$borderPadding, $mapPointNe.y-$borderPadding);
		$activeAreaLatLngNe=$mapProjection.fromPixelToLatLng($activeAreaPointNe, $mapZoomLevel);
		$activeAreaBounds.extend($activeAreaLatLngSw);
		$activeAreaBounds.extend($activeAreaLatLngNe);
	}
	this._activeMarkersChanged=false;
	if(typeof(this._iconBounds[$mapZoomLevel])==='undefined'){
		//	no iconBounds cached for this zoom level
		//	no need to check for existence of individual iconBounds elements
		this._iconBounds[$mapZoomLevel]=[];
		this._activeMarkersChanged=true;	//	force refresh(true) as zoomed to uncached zoom level
		for(i=this._mapMarkers.length-1; i>=0; i--){
			$marker=this._mapMarkers[i];
			$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;
			$marker._makeVisible=$marker._isActive;
			if($marker._isActive){
				$uncachedIconBoundsIndexes.push(i);
			}
		}
	}else{
		//	icondBounds array exists for this zoom level
		//	check for existence of individual iconBounds elements
		for(i=this._mapMarkers.length-1; i>=0; i--){
			$marker=this._mapMarkers[i];
			$oldState=$marker._isActive;
			$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;
			$marker._makeVisible=$marker._isActive;
			if(!this._activeMarkersChanged && $oldState!==$marker._isActive){
				this._activeMarkersChanged=true;
			}
			if($marker._isActive && typeof(this._iconBounds[$mapZoomLevel][i])==='undefined'){
				$uncachedIconBoundsIndexes.push(i);
			}
		}
	}
	return $uncachedIconBoundsIndexes;
};

ClusterMarker.prototype._filterIntersectingMapMarkers=function(){
	var $clusterGroup, i, j, $mapZoomLevel=this._map.getZoom();
	for(i=this._mapMarkers.length-1; i>0; i--)
	{
		if(this._mapMarkers[i]._makeVisible){
			$clusterGroup=[];
			for(j=i-1; j>=0; j--){
				if(this._mapMarkers[j]._makeVisible && this._iconBounds[$mapZoomLevel][i].intersects(this._iconBounds[$mapZoomLevel][j])){
					$clusterGroup.push(j);
				}
			}
			
			//XXX Changes By Aloise Lod
			if( ( $clusterGroup.length > 0 ) && ( $clusterGroup.length >= this.minMarkersPerCluster ) ){
				$clusterGroup.push(i);
				for(j=$clusterGroup.length-1; j>=0; j--){
					this._mapMarkers[$clusterGroup[j]]._makeVisible=false;
				}
				this._clusterMarkers.push(this._clusterMarker($clusterGroup));
			}
			
		}
	}
};

ClusterMarker.prototype.fitMapToMarkers=function(){
	var $markers=this._mapMarkers, $markersBounds=new GLatLngBounds(), i;
	for(i=$markers.length-1; i>=0; i--){
		$markersBounds.extend($markers[i].getLatLng());
	}
	var $fitMapToMarkersZoom=this._map.getBoundsZoomLevel($markersBounds);
		
	if(this.fitMapMaxZoom && $fitMapToMarkersZoom>this.fitMapMaxZoom){
		$fitMapToMarkersZoom=this.fitMapMaxZoom;
	}
	this._map.setCenter($markersBounds.getCenter(), $fitMapToMarkersZoom);
	this.refresh();
};

ClusterMarker.prototype._mapTypeChanged=function(){
	this.refresh(true);
};

ClusterMarker.prototype._moveEnd=function(){
	if(!this._cancelMoveEnd){
		this.refresh();
	}else{
		this._cancelMoveEnd=false;
	}
};

ClusterMarker.prototype._preCacheIconBounds=function($indexes){
	var $mapProjection=this._map.getCurrentMapType().getProjection(), $mapZoomLevel=this._map.getZoom(), i, $marker, $iconSize, $iconAnchorPoint, $iconAnchorPointOffset, $iconBoundsPointSw, $iconBoundsPointNe, $iconBoundsLatLngSw, $iconBoundsLatLngNe, $intersectPadding=this.intersectPadding;
	for(i=$indexes.length-1; i>=0; i--){
		$marker=this._mapMarkers[$indexes[i]];
		$iconSize=$marker.getIcon().iconSize;
		$iconAnchorPoint=$mapProjection.fromLatLngToPixel($marker.getLatLng(), $mapZoomLevel);
		$iconAnchorPointOffset=$marker.getIcon().iconAnchor;
		$iconBoundsPointSw=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x-$intersectPadding, $iconAnchorPoint.y-$iconAnchorPointOffset.y+$iconSize.height+$intersectPadding);
		$iconBoundsPointNe=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x+$iconSize.width+$intersectPadding, $iconAnchorPoint.y-$iconAnchorPointOffset.y-$intersectPadding);
		$iconBoundsLatLngSw=$mapProjection.fromPixelToLatLng($iconBoundsPointSw, $mapZoomLevel);
		$iconBoundsLatLngNe=$mapProjection.fromPixelToLatLng($iconBoundsPointNe, $mapZoomLevel);
		this._iconBounds[$mapZoomLevel][$indexes[i]]=new GLatLngBounds($iconBoundsLatLngSw, $iconBoundsLatLngNe);
	}
};

ClusterMarker.prototype.refresh=function($forceFullRefresh){
	var i,$marker, $uncachedIconBoundsIndexes=this._filterActiveMapMarkers();
	if(this._activeMarkersChanged || $forceFullRefresh){
		this._removeClusterMarkers();
		if(this.clusteringEnabled && this._map.getZoom()<this._map.getCurrentMapType().getMaximumResolution()){
			if($uncachedIconBoundsIndexes.length>0){
				this._preCacheIconBounds($uncachedIconBoundsIndexes);
			}
			this._filterIntersectingMapMarkers();
		}
		for(i=this._clusterMarkers.length-1; i>=0; i--){
			this._map.addOverlay(this._clusterMarkers[i]);
		}
		for(i=this._mapMarkers.length-1; i>=0; i--){
			$marker=this._mapMarkers[i];
			if(!$marker._isVisible && $marker._makeVisible){
				this._map.addOverlay($marker);
				$marker._isVisible=true;
			}
			if($marker._isVisible && !$marker._makeVisible){
				this._map.removeOverlay($marker);
				$marker._isVisible=false;
			}
		}
	}
};

ClusterMarker.prototype._removeClusterMarkers=function(){
	for(var i=this._clusterMarkers.length-1; i>=0; i--){
		this._map.removeOverlay(this._clusterMarkers[i]);
	}
	for(i=this._eventListeners.length-1; i>=0; i--){
		GEvent.removeListener(this._eventListeners[i]);
	}
	this._clusterMarkers=[];
	this._eventListeners=[];
};

ClusterMarker.prototype.clearMarkers = ClusterMarker.prototype.removeMarkers=function(){
	for(var i=this._mapMarkers.length-1; i>=0; i--){
		if(this._mapMarkers[i]. _isVisible){
			this._map.removeOverlay(this._mapMarkers[i]);
		}
		delete this._mapMarkers[i]._isVisible;
		delete this._mapMarkers[i]._isActive;
		delete this._mapMarkers[i]._makeVisible;
	}
	this._removeClusterMarkers();
	this._mapMarkers=[];
	this._iconBounds=[];
};

ClusterMarker.prototype.removeMarker = function( marker )
{
	for(var i=this._mapMarkers.length-1; i>=0; i--)
	{
		if(this._mapMarkers[i] == marker )
		{
			this._map.removeOverlay(this._mapMarkers[i]);
			this._mapMarkers.splice(i,1);
			return true;
		}
	}	
	return false;
}

ClusterMarker.prototype.removeMarkers = function( markers )
{
	if( markers )
	{
		for(i in markers)
		{
			this.removeMarker( markers[i] );
		}
	}
	else
	{
		this.clearMarkers();
	}
}


ClusterMarker.prototype.triggerClick=function($index){
	var $marker=this._mapMarkers[$index];
	if($marker._isVisible){
		//	$marker is visible
		GEvent.trigger($marker, 'click');
	}
	else if($marker._isActive){
		//	$marker is clustered
		this._map.setCenter($marker.getLatLng());
		this._map.zoomIn();
		this.triggerClick($index);
	}else{
		// $marker is not within active area (map bounds + border padding)
		this._map.setCenter($marker.getLatLng());
		this.triggerClick($index);
	}
};



ClusterMarker.prototype._zoomEnd=function(){
	this._cancelMoveEnd=true;
	this.refresh(true);
};



function PropertyMap( options )
{
	if( typeof(options) == "undefined" )
	{
		options = { };
	}


	this.managerParamsPerZoomLevel = options.managerParamsPerZoomLevel ? options.managerParamsPerZoomLevel : 
	{
		"default"	: { minMarkersPerCluster : 2 , intersectPadding : 8  },
		"9" 		: { minMarkersPerCluster : 8 , intersectPadding : 10  },				
		"10" 		: { minMarkersPerCluster : 10 , intersectPadding : 10  },				
		"11" 		: { minMarkersPerCluster : 15 , intersectPadding : 10  },				
		"12" 		: { minMarkersPerCluster : 20 , intersectPadding : 10  },
		"13" 		: { minMarkersPerCluster : 25 , intersectPadding : 10  },
		"14" 		: { minMarkersPerCluster : 30 , intersectPadding : 10  },
		"15" 		: { minMarkersPerCluster : 1000 , intersectPadding : 10  },
		"16" 		: { minMarkersPerCluster : 1000 , intersectPadding : 10  },
		"17" 		: { minMarkersPerCluster : 1000 , intersectPadding : 10  },
		"18" 		: { minMarkersPerCluster : 1000 , intersectPadding : 10  }
	};
	
	this.clusterIcon 			= options.clusterIcon ? options.clusterIcon : new GIcon( null , G_DEFAULT_ICON ) ;
	this.clusterIconMouseOver	= options.clusterIconMouseOver ? options.clusterIconMouseOver : new GIcon( null , G_DEFAULT_ICON ) ;
	this.propertyIcon			= options.propertyIcon ? options.propertyIcon : new GIcon( null , G_DEFAULT_ICON ) ;
	this.propertyIconMouseOver	= options.propertyIconMouseOver ? options.propertyIconMouseOver : new GIcon( null , G_DEFAULT_ICON ) ;
	this.propertyIconSelected	= options.propertyIconSelected ? options.propertyIconSelected : new GIcon( null , G_DEFAULT_ICON ) ;
	this.propertyIconVisited	= options.propertyIconVisited ? options.propertyIconVisited : new GIcon( null , G_DEFAULT_ICON ) ;
	
	this.accommodationTypes 	= options.accommodationTypes ? options.accommodationTypes : null;
	
	this.defaultZoom			= options.defaultZoom ? options.defaultZoom : 6 ; // 7
	
	this.defaultLatitude		= options.defaultLatitude ? options.defaultLatitude : 40;
	this.defaultLongitude		= options.defaultLongitude ? options.defaultLongitude : 4;
	
	this.refPlaceInfo			= options.refPlaceInfo ? options.refPlaceInfo : null;
	
	this.specialPlaces			= options.specialPlaces ? options.specialPlaces : null;
	
	this.currentPropertyId		= options.currentPropertyId ? options.currentPropertyId : null;
	
	this.requestParams 			= options.requestParams ? options.requestParams : [];
	
	this.properties				= options.properties ? options.properties : null;
	 
	this.googleContainerId		= options.googleContainerId ? options.googleContainerId : null;
	
	this.infoWindowMaxWidth		= options.infoWindowMaxWidth ? options.infoWindowMaxWidth : 200;
	
	this.selectedPropertyId		= options.selectedPropertyId ? options.selectedPropertyId : null;
	
	
	this.manager 			= null;
	this.markers 			= null;
	this.currentCluster 	= null;
	this.map				= null;
	
	
    if ( document.getElementById( this.googleContainerId ) && GBrowserIsCompatible() ) 
    {
     
     
      
        var lat				= this.defaultLatitude;
        var long 			= this.defaultLongitude;
        var zoom 			= this.defaultZoom;
        var fitToMarkers	= true;		
              
        if( this.requestParams["lat"] && this.requestParams["long"] && this.requestParams["zoom"] )
        {
        	lat 	= parseFloat( this.requestParams["lat"] );
        	long	= parseFloat( this.requestParams["long"] );
        	zoom 	= parseInt  ( this.requestParams["zoom"] );
        	fitToMarkers = false;
        }
        else if( this.selectedPropertyId && this.properties[ this.selectedPropertyId ] )
        {
        	var selectedProperty = this.properties[ this.selectedPropertyId ];
        	lat		=  selectedProperty.Property.latitude;
        	long 	=  selectedProperty.Property.longitude;
        	fitToMarkers = false;
        }
        else if( this.refPlaceInfo && this.refPlaceInfo.location )
        {
        	lat		= this.refPlaceInfo.location.city_latitude;
        	long	= this.refPlaceInfo.location.city_longitude;
        	zoom 	= this.defaultZoom + 3;
        	fitToMarkers = false;
        }
        

		// $(window).resize(  resizeWindow  );
        // resizeWindow();
              
        this.map = new GMap2( document.getElementById( this.googleContainerId ) );
        this.map.setCenter( new GLatLng( lat, long ), zoom );
        
        
        // map.addControl(new GLargeMapControl());		
        // map.addControl( new GOverviewMapControl());
        
        this.map.addControl(new GSmallMapControl());
        this.map.addControl(new GMapTypeControl());    
        this.map.enableContinuousZoom();
        
        var params = this.managerParamsPerZoomLevel[zoom] ? this.managerParamsPerZoomLevel[zoom] : this.managerParamsPerZoomLevel["default"];
        
        this.manager = new ClusterMarker( this.map , 
        { 
        	clusteringEnabled 		: true , 
        	intersectPadding 		: params.intersectPadding , 
        	minMarkersPerCluster 	: params.minMarkersPerCluster ,  
        	// clusterMarkerClick 	: clusterClick ,  // ZoomIn Info window 
        	clusterMarkerIcon 		: this.clusterIcon , 
        	clusterMarkerTitle		: "Click to zoom in and see %count properties"
        } );
        
        //initMarkers();		
        //bookmarkLinkRefresh();        
        
        
        // manager.refresh(true);
        
        GEvent.bind( this.map , "zoomend" , this, this.zoomChanged );
        
        
        // GEvent.addListener( map , "move" , bookmarkLinkRefresh );
        
		// $("form input:checkbox").click( accommodationTypeClick );
        // $("form input#clearAll").click( function(){ $("form input:checkbox").removeAttr("checked"); accommodationTypeClick(); return false; } );
        // $("form input#selectAll").click( function(){ $("form input:checkbox").attr("checked","checked"); $("form input#accommodation_pool").removeAttr("checked"); accommodationTypeClick(); return false; } );
        // $("a#bookmarkLink").click( function(){ $("div#bookmarkCopyWindow").show(); $("#bookmarkCopyWindow input:text").select(); return false; } );
        // $("#bookmarkCopyWindow a.close").click( function(){ $("div#bookmarkCopyWindow").hide(); return false; } );
        
        
        this.accommodationTypeClick(); // this will initialize markers
        
        
        if( fitToMarkers && markers.length )
        {
	        this.manager.fitMapToMarkers();
	        this.map.setZoom( this.defaultZoom );
        }
        
        
        if( this.requestParams["property"] && this.properties[ this.requestParams["property"] ] )
        {
        	for(i in this.markers)
        	{
        		if( this.markers[i].location == this.properties[ this.requestParams["property"] ])
        		{
        			GEvent.trigger( this.markers[i] , "click" );
        			break;
        		}
        	}
        }		        		        
        
        // $("body").attr( "scroll" , "no" );
        // $("form").submit( function(){ return false; } );
        // $("form input:submit").click( selectSpecialPlace );
        
   }	
	
	
	
} 




PropertyMap.prototype.getArrayIntersection = function (aSet1, aSet2) 
{
  var temp = [];
  var offset = arguments.length - 1;
  var response = [];
  for (var i = 0; i < arguments.length; i++) 
  {
    temp = temp.concat(arguments[i]);
  }

  temp.sort();
  /*
   * The goal is to find an ordered sequence of n identical members of temp,
   * where n = arguments.length.  For this, we just need to check the start
   * and end points of the sequence, and if they match, push them on to the
   * response array.
   */

  for (var i = 0; i < temp.length - offset; i++) 
  {
    if (temp[i] == temp[i + offset])
    {
      response.push(temp[i]);
      i += offset;
    }
  }

  return response;
}


PropertyMap.prototype.zoomInClick = function ( clusterMarker , infoWindow )
{
	var infoWindow = $(infoWindow).parent();
	var ch = null;
 
	this.manager.defaultMarkerClick( clusterMarker );

} 			
		
PropertyMap.prototype.clusterClick = function ( arg )
{
	this.currentCluster = arg;

}				
	
	
PropertyMap.prototype.propertyMarkerInfoWindowClose =	function ()
{

	if( this.PropertyMap.currentPropertyId == this.location.id )
	{
		this.PropertyMap.currentPropertyId = null;
	}
	this.PropertyMap.bookmarkLinkRefresh();
}
	
PropertyMap.prototype.getPropertyMarker = function ( prop )
{
	
    var marker = new GMarker(new GLatLng( parseFloat( prop.Property.latitude ) , parseFloat( prop.Property.longitude ) ) , { icon : ( this.selectedPropertyId ==  prop.Property.id ? this.propertyIconSelected : this.propertyIcon ) , title : prop.Property.title + " - click for details" } );
    marker.PropertyMap = this;
    marker.location = prop;
	
	GEvent.addListener ( marker , "click" , this.markerClick );
	GEvent.addListener ( marker , "infowindowclose" ,  this.propertyMarkerInfoWindowClose );
	
	GEvent.addListener ( marker , "mouseover" , this.propertyMarkerMouseOver );
	GEvent.addListener ( marker , "mouseout"  , this.propertyMarkerMouseOut );
	
	return marker;	        

}	
	
	
PropertyMap.prototype.propertyMarkerMouseOver = function ( point , marker  )
{
	if( this.location.Property.id == this.PropertyMap.selectedPropertyId )
	{
		// empty
	}
	else
	{
		this.setImage( this.PropertyMap.propertyIconMouseOver.image );
	}
}	

PropertyMap.prototype.propertyMarkerMouseOut = function ( point )
{
	if( this.location.Property.id == this.PropertyMap.selectedPropertyId )
	{
		// the same thing
	}
	else if( this.visited )
	{
		this.setImage( this.PropertyMap.propertyIconVisited.image );
	}
	else
	{
		this.setImage( this.PropertyMap.propertyIcon.image );
	}
}
	
	
PropertyMap.prototype.initMarkers = function ( propIds )
{
 	markers = new Array();
 	this.manager.removeMarkers();

	if( propIds && ( propIds.length ) )
	{
		for( i in propIds )
		{
			if( this.properties[ propIds[i] ])
			{
				markers.push( this.getPropertyMarker( properties[ propIds[i] ]));
			}
		}
		this.manager.addMarkers(markers);
	}
	else
	{
		
        for(i in this.properties)
        {
			markers.push( this.getPropertyMarker( this.properties[i] ));
        }
		
        this.manager.addMarkers(markers);
   }
       
       
	this.manager.refresh(true);
}
	
PropertyMap.prototype.removeDuplicates = function (arr)
 {
    //get sorted array as input and returns the same array without duplicates.
    var result=new Array();
    var lastValue="";
    for (var i=0; i<arr.length; i++)
    {
  		var curValue=arr[i];
  		if (curValue != lastValue)
  		{
			result[result.length] = curValue;
  		}
  		lastValue = curValue;
    }
    return result;
 }
   	
PropertyMap.prototype.bookmarkLinkRefresh = function ()
{
   		/*
   		var params = new Array();
   		params.push( "zoom="+map.getZoom() );
   		params.push( "lat="+map.getCenter().lat() );
   		params.push( "long="+map.getCenter().lng() );
   		
   		if( currentPropertyId )
   		{
   			params.push( "property="+ currentPropertyId );
   		}
   		
   		var accTypes = new Array();
   		$("form input:checked").each( function(){ accTypes.push( $(this).val()) } );
   		params.push( "accommodations=" + accTypes.join(",")  );
   		
   		
   		var url = "http://" + window.location.hostname + "/map/" + "?"+params.join("&");
   		
   		$("a#bookmarkLink").attr("href" , url );
   		
   		$("#bookmarkCopyWindow input:text").val( url ).select();	
   		
   		$("a#BookmarkOpenInNewWindow").attr( "href" , url );
   		
   		*/
   		
} 
	
	
PropertyMap.prototype.markerClick =	function ( overlay , point ) 
{
    	// alert(this.location.Title);
    	this.PropertyMap.currentPropertyId = this.location.id ;
    	this.openInfoWindowHtml( "<a href='/"+this.location.Property.reference_id+"' >"+this.location.Property.title+"</a>" , { maxWidth  : this.PropertyMap.infoWindowMaxWidth  } );
    	this.visited = true ;
    	
    	if( this.location.Property.id != this.PropertyMap.selectedPropertyId )
    	{
			this.setImage( this.PropertyMap.propertyIconVisited.image );
		}
		
		this.PropertyMap.bookmarkLinkRefresh();
}
  	
  	
  	
PropertyMap.prototype.accommodationTypeClick  =	function ()
{
		var propIds = new Array();
		
		// var poolSelected =  ( $("form input[@value=pool]:checked").length > 0 );
		// var cnt = $("form input:checked").length;
		// var excludePool = ( cnt > 1 ) && ( poolSelected );
		
		this.initMarkers( );  	
		this.bookmarkLinkRefresh();
}
  	
  	
  	
PropertyMap.prototype.zoomChanged = function (oldLevel,  newLevel)
{
	var params = this.managerParamsPerZoomLevel[newLevel] ? this.managerParamsPerZoomLevel[newLevel] : this.managerParamsPerZoomLevel["default"];
	 
  	this.manager.minMarkersPerCluster = params.minMarkersPerCluster;
  		
  	this.manager.intersectPadding 	 = params.intersectPadding;
  		
  	this.manager.refresh(true);
  	this.bookmarkLinkRefresh();
}
  	


