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;}this.clusterMarkerIcon=new GIcon();this.clusterMarkerIcon.iconSize=new GSize(40,40);this.clusterMarkerIcon.iconAnchor=new GPoint(6,20);this.clusterMarkerIcon.infoWindowAnchor=new GPoint(6,1);this.clusterMarkerTitle=(A.clusterMarkerTitle)?A.clusterMarkerTitle:"Visualizza %count aziende";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,J,K){return new GMarker(L,{icon:J,title:K});}var G=new GLatLngBounds(),C,D,F=[],I,E=this;for(C=B.length-1;C>=0;C--){I=this._mapMarkers[B[C]];I.index=B[C];G.extend(I.getLatLng());F.push(I);}markerCount=B.length;color="#eeff00";if(markerCount<10){color="#eeff00";}else{if(markerCount<50){color="#eeaa00";}else{color="#ee3300";}}var H=MapIconMaker.createFlatIcon({shape:"roundrect",addStar:false,width:32,height:32,labelSize:0,label:""+B.length,primaryColor:color});D=A(G.getCenter(),H,this.clusterMarkerTitle.replace(/%count/gi,B.length));D.clusterGroupBounds=G;this._eventListeners.push(GEvent.addListener(D,"click",function(){E.clusterMarkerClick({clusterMarker:D,clusteredMarkers:F});}));return D;};ClusterMarker.prototype.clusterMarkerClick=function(A){this._map.setCenter(A.clusterMarker.getLatLng(),this._map.getBoundsZoomLevel(A.clusterMarker.clusterGroupBounds));};ClusterMarker.prototype._filterActiveMapMarkers=function(){var H=this.borderPadding,G=this._map.getZoom(),N=this._map.getCurrentMapType().getProjection(),L,B,J,F,K,C,A=this._map.getBounds(),E,M,D=[],I;if(H){L=N.fromLatLngToPixel(A.getSouthWest(),G);B=new GPoint(L.x-H,L.y+H);J=N.fromPixelToLatLng(B,G);F=N.fromLatLngToPixel(A.getNorthEast(),G);K=new GPoint(F.x+H,F.y-H);C=N.fromPixelToLatLng(K,G);A.extend(J);A.extend(C);}this._activeMarkersChanged=false;if(typeof (this._iconBounds[G])==="undefined"){this._iconBounds[G]=[];this._activeMarkersChanged=true;for(E=this._mapMarkers.length-1;E>=0;E--){M=this._mapMarkers[E];M._isActive=A.containsLatLng(M.getLatLng())?true:false;M._makeVisible=M._isActive;if(M._isActive){D.push(E);}}}else{for(E=this._mapMarkers.length-1;E>=0;E--){M=this._mapMarkers[E];I=M._isActive;M._isActive=A.containsLatLng(M.getLatLng())?true:false;M._makeVisible=M._isActive;if(!this._activeMarkersChanged&&I!==M._isActive){this._activeMarkersChanged=true;}if(M._isActive&&typeof (this._iconBounds[G][E])==="undefined"){D.push(E);}}}return D;};ClusterMarker.prototype._filterIntersectingMapMarkers=function(){var D,C,B,A=this._map.getZoom();for(C=this._mapMarkers.length-1;C>0;C--){if(this._mapMarkers[C]._makeVisible){D=[];for(B=C-1;B>=0;B--){if(this._mapMarkers[B]._makeVisible&&this._iconBounds[A][C].intersects(this._iconBounds[A][B])){D.push(B);}}if(D.length!==0){D.push(C);for(B=D.length-1;B>=0;B--){this._mapMarkers[D[B]]._makeVisible=false;}this._clusterMarkers.push(this._clusterMarker(D));}}}};ClusterMarker.prototype.fitMapToMarkers=function(){var C=this._mapMarkers,D=new GLatLngBounds(),B;for(B=C.length-1;B>=0;B--){D.extend(C[B].getLatLng());}var A=this._map.getBoundsZoomLevel(D);if(this.fitMapMaxZoom&&A>this.fitMapMaxZoom){A=this.fitMapMaxZoom;}this._map.setCenter(D.getCenter(),A);this.refresh();stopLoading();};ClusterMarker.prototype._mapTypeChanged=function(){this.refresh(true);};ClusterMarker.prototype._moveEnd=function(){if(!this._cancelMoveEnd){this.refresh();}else{this._cancelMoveEnd=false;}};ClusterMarker.prototype._preCacheIconBounds=function(B){var L=this._map.getCurrentMapType().getProjection(),G=this._map.getZoom(),F,M,D,A,H,J,E,I,C,K=this.intersectPadding;for(F=B.length-1;F>=0;F--){M=this._mapMarkers[B[F]];D=M.getIcon().iconSize;A=L.fromLatLngToPixel(M.getLatLng(),G);H=M.getIcon().iconAnchor;J=new GPoint(A.x-H.x-K,A.y-H.y+D.height+K);E=new GPoint(A.x-H.x+D.width+K,A.y-H.y-K);I=L.fromPixelToLatLng(J,G);C=L.fromPixelToLatLng(E,G);this._iconBounds[G][B[F]]=new GLatLngBounds(I,C);}};ClusterMarker.prototype.refresh=function(D){var C,B,A=this._filterActiveMapMarkers();if(this._activeMarkersChanged||D){this._removeClusterMarkers();if(this.clusteringEnabled&&this._map.getZoom()<this._map.getCurrentMapType().getMaximumResolution()){if(A.length>0){this._preCacheIconBounds(A);}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(){for(var A=this._clusterMarkers.length-1;A>=0;A--){this._map.removeOverlay(this._clusterMarkers[A]);}for(A=this._eventListeners.length-1;A>=0;A--){GEvent.removeListener(this._eventListeners[A]);}this._clusterMarkers=[];this._eventListeners=[];};ClusterMarker.prototype.removeMarkers=function(){for(var A=this._mapMarkers.length-1;A>=0;A--){if(this._mapMarkers[A]._isVisible){this._map.removeOverlay(this._mapMarkers[A]);}delete this._mapMarkers[A]._isVisible;delete this._mapMarkers[A]._isActive;delete this._mapMarkers[A]._makeVisible;}this._removeClusterMarkers();this._mapMarkers=[];this._iconBounds=[];};ClusterMarker.prototype.triggerClick=function(A){var B=this._mapMarkers[A];if(B._isVisible){GEvent.trigger(B,"click");}else{if(B._isActive){this._map.setCenter(B.getLatLng());this._map.zoomIn();this.triggerClick(A);}else{this._map.setCenter(B.getLatLng());this.triggerClick(A);}}};ClusterMarker.prototype._zoomEnd=function(){this._cancelMoveEnd=true;this.refresh(true);};