function ClusterMarker(b,a){this._map=b;this._mapMarkers=[];this._iconBounds=[];this._clusterMarkers=[];this._eventListeners=[];if(typeof(a)==="undefined"){a={}}this.borderPadding=(a.borderPadding)?a.borderPadding:256;this.clusteringEnabled=(a.clusteringEnabled===false)?false:true;if(a.clusterMarkerClick){this.clusterMarkerClick=a.clusterMarkerClick}if(a.clusterMarkerIcon){this.clusterMarkerIcon=a.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=(a.clusterMarkerTitle)?a.clusterMarkerTitle:"Click to zoom in and see %count markers";if(a.fitMapMaxZoom){this.fitMapMaxZoom=a.fitMapMaxZoom}this.intersectPadding=(a.intersectPadding)?a.intersectPadding:0;if(a.markers){this.addMarkers(a.markers)}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(b){var a;if(!b[0]){var c=[];for(a in b){c.push(b[a])}b=c}for(a=b.length-1;a>=0;a--){b[a]._isVisible=false;b[a]._isActive=false;b[a]._makeVisible=false}this._mapMarkers=this._mapMarkers.concat(b)};ClusterMarker.prototype._clusterMarker=function(b){function a(l,i,k){return new GMarker(l,{icon:i,title:k})}var h=new GLatLngBounds(),d,e,g=[],j,f=this,c=this._mapMarkers;for(d=b.length-1;d>=0;d--){j=c[b[d]];j.index=b[d];h.extend(j.getLatLng());g.push(j)}e=a(h.getCenter(),this.clusterMarkerIcon,this.clusterMarkerTitle.replace(/%count/gi,b.length));e.clusterGroupBounds=h;this._eventListeners.push(GEvent.addListener(e,"click",function(){f.clusterMarkerClick({clusterMarker:e,clusteredMarkers:g})}));e._childIndexes=b;for(d=b.length-1;d>=0;d--){c[b[d]]._parentCluster=e}return e};ClusterMarker.prototype.clusterMarkerClick=function(a){this._map.setCenter(a.clusterMarker.getLatLng(),this._map.getBoundsZoomLevel(a.clusterMarker.clusterGroupBounds))};ClusterMarker.prototype._filterActiveMapMarkers=function(){var k=this.borderPadding,j=this._map.getZoom(),q=this._map.getCurrentMapType().getProjection(),o,c,m,h,n,d,b=this._map.getBounds(),f,p,e=[],l,a=this._mapMarkers,g=this._iconBounds;if(k){o=q.fromLatLngToPixel(b.getSouthWest(),j);c=new GPoint(o.x-k,o.y+k);m=q.fromPixelToLatLng(c,j);h=q.fromLatLngToPixel(b.getNorthEast(),j);n=new GPoint(h.x+k,h.y-k);d=q.fromPixelToLatLng(n,j);b.extend(m);b.extend(d)}this._activeMarkersChanged=false;if(typeof(g[j])==="undefined"){this._iconBounds[j]=[];this._activeMarkersChanged=true;for(f=a.length-1;f>=0;f--){p=a[f];p._isActive=b.containsLatLng(p.getLatLng())?true:false;p._makeVisible=p._isActive;if(p._isActive){e.push(f)}}}else{for(f=a.length-1;f>=0;f--){p=a[f];l=p._isActive;p._isActive=b.containsLatLng(p.getLatLng())?true:false;p._makeVisible=p._isActive;if(!this._activeMarkersChanged&&l!==p._isActive){this._activeMarkersChanged=true}if(p._isActive&&typeof(g[j][f])==="undefined"){e.push(f)}}}return e};ClusterMarker.prototype._filterIntersectingMapMarkers=function(){var e,d,b,a=this._map.getZoom(),f=this._mapMarkers,c=this._iconBounds;for(d=f.length-1;d>0;d--){if(f[d]._makeVisible){e=[];for(b=d-1;b>=0;b--){if(f[b]._makeVisible&&c[a][d].intersects(c[a][b])){e.push(b)}}if(e.length!==0){e.push(d);for(b=e.length-1;b>=0;b--){f[e[b]]._makeVisible=false}this._clusterMarkers.push(this._clusterMarker(e))}}}};ClusterMarker.prototype.fitMapToMarkers=function(){var d=this._mapMarkers,c=new GLatLngBounds(),b;for(b=d.length-1;b>=0;b--){c.extend(d[b].getLatLng())}var a=this._map.getBoundsZoomLevel(c);if(this.fitMapMaxZoom&&a>this.fitMapMaxZoom){a=this.fitMapMaxZoom}this._map.setCenter(c.getCenter(),a);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(c,h){var n=this._map.getCurrentMapType().getProjection(),g,o,e,a,j,l,f,k,d,m=this.intersectPadding,b=this._mapMarkers;for(g=c.length-1;g>=0;g--){o=b[c[g]];e=o.getIcon().iconSize;a=n.fromLatLngToPixel(o.getLatLng(),h);j=o.getIcon().iconAnchor;l=new GPoint(a.x-j.x-m,a.y-j.y+e.height+m);f=new GPoint(a.x-j.x+e.width+m,a.y-j.y-m);k=n.fromPixelToLatLng(l,h);d=n.fromPixelToLatLng(f,h);this._iconBounds[h][c[g]]=new GLatLngBounds(k,d)}};ClusterMarker.prototype.refresh=function(d){var c,b,e=this._map.getZoom(),a=this._filterActiveMapMarkers();if(this._activeMarkersChanged||d){this._removeClusterMarkers();if(this.clusteringEnabled&&e<this._map.getCurrentMapType().getMaximumResolution()){if(a.length>0){this._preCacheIconBounds(a,e)}this._filterIntersectingMapMarkers()}for(c=this._clusterMarkers.length-1;c>=0;c--){this._map.addOverlay(this._clusterMarkers[c])}for(c=this._mapMarkers.length-1;c>=0;c--){b=this._mapMarkers[c];if(!b._isVisible&&b._makeVisible){this._map.addOverlay(b);b._isVisible=true}if(b._isVisible&&!b._makeVisible){this._map.removeOverlay(b);b._isVisible=false}}}};ClusterMarker.prototype._removeClusterMarkers=function(){var d,b,g=this._map,a=this._eventListeners,f=this._clusterMarkers,c,e=this._mapMarkers;for(d=f.length-1;d>=0;d--){c=f[d]._childIndexes;for(b=c.length-1;b>=0;b--){delete e[c[b]]._parentCluster}g.removeOverlay(f[d])}for(d=a.length-1;d>=0;d--){GEvent.removeListener(a[d])}this._clusterMarkers=[];this._eventListeners=[]};ClusterMarker.prototype.removeMarkers=function(){var a,b=this._mapMarkers,c=this._map;for(a=b.length-1;a>=0;a--){if(b[a]._isVisible){c.removeOverlay(b[a])}delete b[a]._isVisible;delete b[a]._isActive;delete b[a]._makeVisible}this._removeClusterMarkers();this._mapMarkers=[];this._iconBounds=[]};ClusterMarker.prototype.triggerClick=function(h){var k=this._mapMarkers[h];if(k._isVisible){GEvent.trigger(k,"click")}else{if(k._isActive){var f=k._parentCluster._childIndexes,b=true,c,d,g=this._map.getZoom(),j,e=this._iconBounds,a=this._map.getCurrentMapType().getMaximumResolution();while(b&&g<a){b=false;g++;if(typeof(e[g])==="undefined"){e[g]=[];this._preCacheIconBounds(f,g)}else{c=[];for(d=f.length-1;d>=0;d--){if(typeof(e[g][f[d]])==="undefined"){c.push(f[d])}}if(c.length>=1){this._preCacheIconBounds(c,g)}}for(d=f.length-1;d>=0;d--){j=f[d];if(j!==h&&e[g][j].intersects(e[g][h])){b=true;break}}}this._map.setCenter(k.getLatLng(),g);this.triggerClick(h)}else{this._map.setCenter(k.getLatLng());this.triggerClick(h)}}};ClusterMarker.prototype._zoomEnd=function(){this._cancelMoveEnd=true;this.refresh(true)};