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