function MarkerClusterer(a,b,c){this.extend(MarkerClusterer,google.maps.OverlayView);this.map_=a;this.markers_=[];this.clusters_=[];this.sizes=[53,56,66,78,90];this.styles_=[];this.ready_=!1;c=c||{};this.gridSize_=c.gridSize||60;this.minClusterSize_=c.minimumClusterSize||2;this.maxZoom_=c.maxZoom||null;this.styles_=c.styles||[];this.imagePath_=c.imagePath||this.MARKER_CLUSTER_IMAGE_PATH_;this.imageExtension_=c.imageExtension||this.MARKER_CLUSTER_IMAGE_EXTENSION_;this.zoomOnClick_=!0;void 0!=c.zoomOnClick&&
(this.zoomOnClick_=c.zoomOnClick);this.averageCenter_=!1;void 0!=c.averageCenter&&(this.averageCenter_=c.averageCenter);this.setupStyles_();this.setMap(a);this.prevZoom_=this.map_.getZoom();var d=this;google.maps.event.addListener(this.map_,"zoom_changed",function(){var a=d.map_.getZoom();d.prevZoom_!=a&&(d.prevZoom_=a,d.resetViewport())});google.maps.event.addListener(this.map_,"idle",function(){d.redraw()});b&&b.length&&this.addMarkers(b,!1)}
MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m";MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_EXTENSION_="png";MarkerClusterer.prototype.extend=function(a,b){return function(a){for(var b in a.prototype)this.prototype[b]=a.prototype[b];return this}.apply(a,[b])};MarkerClusterer.prototype.onAdd=function(){this.setReady_(!0)};MarkerClusterer.prototype.draw=function(){};
MarkerClusterer.prototype.setupStyles_=function(){if(!this.styles_.length)for(var a=0,b;b=this.sizes[a];a++)this.styles_.push({url:this.imagePath_+(a+1)+"."+this.imageExtension_,height:b,width:b})};MarkerClusterer.prototype.fitMapToMarkers=function(){for(var a=this.getMarkers(),b=new google.maps.LatLngBounds,c=0,d;d=a[c];c++)b.extend(d.getPosition());this.map_.fitBounds(b)};MarkerClusterer.prototype.setStyles=function(a){this.styles_=a};MarkerClusterer.prototype.getStyles=function(){return this.styles_};
MarkerClusterer.prototype.isZoomOnClick=function(){return this.zoomOnClick_};MarkerClusterer.prototype.isAverageCenter=function(){return this.averageCenter_};MarkerClusterer.prototype.getMarkers=function(){return this.markers_};MarkerClusterer.prototype.getTotalMarkers=function(){return this.markers_.length};MarkerClusterer.prototype.setMaxZoom=function(a){this.maxZoom_=a};MarkerClusterer.prototype.getMaxZoom=function(){return this.maxZoom_};
MarkerClusterer.prototype.calculator_=function(a,b){for(var c=0,d=a.length,e=d;0!==e;)e=parseInt(e/10,10),c++;c=Math.min(c,b);return{text:d,index:c}};MarkerClusterer.prototype.setCalculator=function(a){this.calculator_=a};MarkerClusterer.prototype.getCalculator=function(){return this.calculator_};MarkerClusterer.prototype.addMarkers=function(a,b){for(var c=0,d;d=a[c];c++)this.pushMarkerTo_(d);b||this.redraw()};
MarkerClusterer.prototype.pushMarkerTo_=function(a){a.isAdded=!1;if(a.draggable){var b=this;google.maps.event.addListener(a,"dragend",function(){a.isAdded=!1;b.repaint()})}this.markers_.push(a)};MarkerClusterer.prototype.addMarker=function(a,b){this.pushMarkerTo_(a);b||this.redraw()};
MarkerClusterer.prototype.removeMarker_=function(a){var b=-1;if(this.markers_.indexOf)b=this.markers_.indexOf(a);else for(var c=0,d;d=this.markers_[c];c++)if(d==a){b=c;break}if(-1==b)return!1;a.setMap(null);this.markers_.splice(b,1);return!0};MarkerClusterer.prototype.removeMarker=function(a,b){var c=this.removeMarker_(a);return!b&&c?(this.resetViewport(),this.redraw(),!0):!1};
MarkerClusterer.prototype.removeMarkers=function(a,c){for(var b=!1,d=0,e;e=a[d];d++)e=this.removeMarker_(e),b=b||e;if(!c&&b)return this.resetViewport(),this.redraw(),!0};MarkerClusterer.prototype.setReady_=function(a){this.ready_||(this.ready_=a,this.createClusters_())};MarkerClusterer.prototype.getTotalClusters=function(){return this.clusters_.length};MarkerClusterer.prototype.getMap=function(){return this.map_};MarkerClusterer.prototype.setMap=function(a){this.map_=a};
MarkerClusterer.prototype.getGridSize=function(){return this.gridSize_};MarkerClusterer.prototype.setGridSize=function(a){this.gridSize_=a};MarkerClusterer.prototype.getMinClusterSize=function(){return this.minClusterSize_};MarkerClusterer.prototype.setMinClusterSize=function(a){this.minClusterSize_=a};
MarkerClusterer.prototype.getExtendedBounds=function(a){var c=this.getProjection(),b=new google.maps.LatLng(a.getNorthEast().lat(),a.getNorthEast().lng()),d=new google.maps.LatLng(a.getSouthWest().lat(),a.getSouthWest().lng()),b=c.fromLatLngToDivPixel(b);b.x+=this.gridSize_;b.y-=this.gridSize_;d=c.fromLatLngToDivPixel(d);d.x-=this.gridSize_;d.y+=this.gridSize_;b=c.fromDivPixelToLatLng(b);c=c.fromDivPixelToLatLng(d);a.extend(b);a.extend(c);return a};
MarkerClusterer.prototype.isMarkerInBounds_=function(a,c){return c.contains(a.getPosition())};MarkerClusterer.prototype.clearMarkers=function(){this.resetViewport(!0);this.markers_=[]};MarkerClusterer.prototype.resetViewport=function(a){for(var c=0,b;b=this.clusters_[c];c++)b.remove();for(c=0;b=this.markers_[c];c++)b.isAdded=!1,a&&b.setMap(null);this.clusters_=[]};
MarkerClusterer.prototype.repaint=function(){var a=this.clusters_.slice();this.clusters_.length=0;this.resetViewport();this.redraw();window.setTimeout(function(){for(var c=0,b;b=a[c];c++)b.remove()},0)};MarkerClusterer.prototype.redraw=function(){this.createClusters_()};
MarkerClusterer.prototype.distanceBetweenPoints_=function(a,c){if(!a||!c)return 0;var b=(c.lat()-a.lat())*Math.PI/180,d=(c.lng()-a.lng())*Math.PI/180,b=Math.sin(b/2)*Math.sin(b/2)+Math.cos(a.lat()*Math.PI/180)*Math.cos(c.lat()*Math.PI/180)*Math.sin(d/2)*Math.sin(d/2);return 6371*2*Math.atan2(Math.sqrt(b),Math.sqrt(1-b))};
MarkerClusterer.prototype.addToClosestCluster_=function(a){var c=4E4,b=null;a.getPosition();for(var d=0,e;e=this.clusters_[d];d++){var f=e.getCenter();f&&(f=this.distanceBetweenPoints_(f,a.getPosition()),f<c&&(c=f,b=e))}b&&b.isMarkerInClusterBounds(a)?b.addMarker(a):(e=new Cluster(this),e.addMarker(a),this.clusters_.push(e))};
MarkerClusterer.prototype.createClusters_=function(){if(this.ready_)for(var a=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast()),a=this.getExtendedBounds(a),c=0,b;b=this.markers_[c];c++)!b.isAdded&&this.isMarkerInBounds_(b,a)&&this.addToClosestCluster_(b)};
function Cluster(a){this.markerClusterer_=a;this.map_=a.getMap();this.gridSize_=a.getGridSize();this.minClusterSize_=a.getMinClusterSize();this.averageCenter_=a.isAverageCenter();this.center_=null;this.markers_=[];this.bounds_=null;this.clusterIcon_=new ClusterIcon(this,a.getStyles(),a.getGridSize())}Cluster.prototype.isMarkerAlreadyAdded=function(a){if(this.markers_.indexOf)return-1!=this.markers_.indexOf(a);for(var c=0,b;b=this.markers_[c];c++)if(b==a)return!0;return!1};
Cluster.prototype.addMarker=function(a){if(this.isMarkerAlreadyAdded(a))return!1;if(this.center_){if(this.averageCenter_){var c=this.markers_.length+1,b=(this.center_.lat()*(c-1)+a.getPosition().lat())/c,c=(this.center_.lng()*(c-1)+a.getPosition().lng())/c;this.center_=new google.maps.LatLng(b,c);this.calculateBounds_()}}else this.center_=a.getPosition(),this.calculateBounds_();a.isAdded=!0;this.markers_.push(a);b=this.markers_.length;b<this.minClusterSize_&&a.getMap()!=this.map_&&a.setMap(this.map_);
if(b==this.minClusterSize_)for(c=0;c<b;c++)this.markers_[c].setMap(null);b>=this.minClusterSize_&&a.setMap(null);this.updateIcon();return!0};Cluster.prototype.getMarkerClusterer=function(){return this.markerClusterer_};
Cluster.prototype.getBounds=function(){for(var a=new google.maps.LatLngBounds(this.center_,this.center_),b=this.getMarkers(),c=0,d;d=b[c];c++)a.extend(d.getPosition());return a};Cluster.prototype.remove=function(){this.clusterIcon_.remove();this.markers_.length=0;delete this.markers_};Cluster.prototype.getSize=function(){return this.markers_.length};Cluster.prototype.getMarkers=function(){return this.markers_};Cluster.prototype.getCenter=function(){return this.center_};
Cluster.prototype.calculateBounds_=function(){var a=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(a)};Cluster.prototype.isMarkerInClusterBounds=function(a){return this.bounds_.contains(a.getPosition())};Cluster.prototype.getMap=function(){return this.map_};
Cluster.prototype.updateIcon=function(){var a=this.map_.getZoom(),b=this.markerClusterer_.getMaxZoom();if(b&&a>b)for(a=0;b=this.markers_[a];a++)b.setMap(this.map_);else this.markers_.length<this.minClusterSize_?this.clusterIcon_.hide():(a=this.markerClusterer_.getStyles().length,a=this.markerClusterer_.getCalculator()(this.markers_,a),this.clusterIcon_.setCenter(this.center_),this.clusterIcon_.setSums(a),this.clusterIcon_.show())};
function ClusterIcon(a,b,c){a.getMarkerClusterer().extend(ClusterIcon,google.maps.OverlayView);this.styles_=b;this.padding_=c||0;this.cluster_=a;this.center_=null;this.map_=a.getMap();this.sums_=this.div_=null;this.visible_=!1;this.setMap(this.map_)}ClusterIcon.prototype.triggerClusterClick=function(){var a=this.cluster_.getMarkerClusterer();google.maps.event.trigger(a,"clusterclick",this.cluster_);a.isZoomOnClick()&&this.map_.fitBounds(this.cluster_.getBounds())};
ClusterIcon.prototype.onAdd=function(){this.div_=document.createElement("DIV");if(this.visible_){var a=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(a);this.div_.innerHTML=this.sums_.text}this.getPanes().overlayMouseTarget.appendChild(this.div_);var b=this;google.maps.event.addDomListener(this.div_,"click",function(){b.triggerClusterClick()})};
ClusterIcon.prototype.getPosFromLatLng_=function(a){a=this.getProjection().fromLatLngToDivPixel(a);a.x-=parseInt(this.width_/2,10);a.y-=parseInt(this.height_/2,10);return a};ClusterIcon.prototype.draw=function(){if(this.visible_){var a=this.getPosFromLatLng_(this.center_);this.div_.style.top=a.y+"px";this.div_.style.left=a.x+"px"}};ClusterIcon.prototype.hide=function(){this.div_&&(this.div_.style.display="none");this.visible_=!1};
ClusterIcon.prototype.show=function(){if(this.div_){var a=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(a);this.div_.style.display=""}this.visible_=!0};ClusterIcon.prototype.remove=function(){this.setMap(null)};ClusterIcon.prototype.onRemove=function(){this.div_&&this.div_.parentNode&&(this.hide(),this.div_.parentNode.removeChild(this.div_),this.div_=null)};
ClusterIcon.prototype.setSums=function(a){this.sums_=a;this.text_=a.text;this.index_=a.index;this.div_&&(this.div_.innerHTML=a.text);this.useStyle()};ClusterIcon.prototype.useStyle=function(){var a=Math.max(0,this.sums_.index-1),a=Math.min(this.styles_.length-1,a),a=this.styles_[a];this.url_=a.url;this.height_=a.height;this.width_=a.width;this.textColor_=a.textColor;this.anchor_=a.anchor;this.textSize_=a.textSize;this.backgroundPosition_=a.backgroundPosition};
ClusterIcon.prototype.setCenter=function(a){this.center_=a};
ClusterIcon.prototype.createCss=function(a){var b=[];b.push("background-image:url("+this.url_+");");b.push("background-position:"+(this.backgroundPosition_?this.backgroundPosition_:"0 0")+";");"object"===typeof this.anchor_?("number"===typeof this.anchor_[0]&&0<this.anchor_[0]&&this.anchor_[0]<this.height_?b.push("height:"+(this.height_-this.anchor_[0])+"px; padding-top:"+this.anchor_[0]+"px;"):b.push("height:"+this.height_+"px; line-height:"+this.height_+"px;"),"number"===typeof this.anchor_[1]&&
0<this.anchor_[1]&&this.anchor_[1]<this.width_?b.push("width:"+(this.width_-this.anchor_[1])+"px; padding-left:"+this.anchor_[1]+"px;"):b.push("width:"+this.width_+"px; text-align:center;")):b.push("height:"+this.height_+"px; line-height:"+this.height_+"px; width:"+this.width_+"px; text-align:center;");b.push("opacity:0.5; cursor:pointer; top:"+a.y+"px; left:"+a.x+"px; color:"+(this.textColor_?this.textColor_:"black")+"; position:absolute; font-size:"+(this.textSize_?this.textSize_:11)+"px; font-family:Arial,sans-serif; font-weight:bold");
return b.join("")};
window.MarkerClusterer=MarkerClusterer;MarkerClusterer.prototype.addMarker=MarkerClusterer.prototype.addMarker;MarkerClusterer.prototype.addMarkers=MarkerClusterer.prototype.addMarkers;MarkerClusterer.prototype.clearMarkers=MarkerClusterer.prototype.clearMarkers;MarkerClusterer.prototype.fitMapToMarkers=MarkerClusterer.prototype.fitMapToMarkers;MarkerClusterer.prototype.getCalculator=MarkerClusterer.prototype.getCalculator;MarkerClusterer.prototype.getGridSize=MarkerClusterer.prototype.getGridSize;
MarkerClusterer.prototype.getExtendedBounds=MarkerClusterer.prototype.getExtendedBounds;MarkerClusterer.prototype.getMap=MarkerClusterer.prototype.getMap;MarkerClusterer.prototype.getMarkers=MarkerClusterer.prototype.getMarkers;MarkerClusterer.prototype.getMaxZoom=MarkerClusterer.prototype.getMaxZoom;MarkerClusterer.prototype.getStyles=MarkerClusterer.prototype.getStyles;MarkerClusterer.prototype.getTotalClusters=MarkerClusterer.prototype.getTotalClusters;
MarkerClusterer.prototype.getTotalMarkers=MarkerClusterer.prototype.getTotalMarkers;MarkerClusterer.prototype.redraw=MarkerClusterer.prototype.redraw;MarkerClusterer.prototype.removeMarker=MarkerClusterer.prototype.removeMarker;MarkerClusterer.prototype.removeMarkers=MarkerClusterer.prototype.removeMarkers;MarkerClusterer.prototype.resetViewport=MarkerClusterer.prototype.resetViewport;MarkerClusterer.prototype.repaint=MarkerClusterer.prototype.repaint;MarkerClusterer.prototype.setCalculator=MarkerClusterer.prototype.setCalculator;
MarkerClusterer.prototype.setGridSize=MarkerClusterer.prototype.setGridSize;MarkerClusterer.prototype.setMaxZoom=MarkerClusterer.prototype.setMaxZoom;MarkerClusterer.prototype.onAdd=MarkerClusterer.prototype.onAdd;MarkerClusterer.prototype.draw=MarkerClusterer.prototype.draw;Cluster.prototype.getCenter=Cluster.prototype.getCenter;Cluster.prototype.getSize=Cluster.prototype.getSize;Cluster.prototype.getMarkers=Cluster.prototype.getMarkers;ClusterIcon.prototype.onAdd=ClusterIcon.prototype.onAdd;
ClusterIcon.prototype.draw=ClusterIcon.prototype.draw;ClusterIcon.prototype.onRemove=ClusterIcon.prototype.onRemove;
