function Fluster2Cluster(b,i){var d=i.getPosition();this.fluster=b;this.markers=[];this.bounds=null;this.marker=null;this.lngSum=0;this.latSum=0;this.center=d;this.map=this.fluster.getMap();var h=this;var f=b.getProjection();var c=b.gridSize;var e=f.fromLatLngToDivPixel(d);var a=new google.maps.Point(e.x-c,e.y+c);var g=new google.maps.Point(e.x+c,e.y-c);this.bounds=new google.maps.LatLngBounds(f.fromDivPixelToLatLng(a),f.fromDivPixelToLatLng(g));this.addMarker=function(j){this.markers.push(j)};this.show=function(){if(this.markers.length==1){this.markers[0].setMap(h.map)}else{if(this.markers.length>1){for(var j=0;j<this.markers.length;j++){this.markers[j].setMap(null)}if(this.marker==null){this.marker=new Fluster2ClusterMarker(this.fluster,this);if(this.fluster.debugEnabled){google.maps.event.addListener(this.marker,"mouseover",h.debugShowMarkers);google.maps.event.addListener(this.marker,"mouseout",h.debugHideMarkers)}}this.marker.show()}}};this.hide=function(){if(this.marker!=null){this.marker.hide()}};this.debugShowMarkers=function(){for(var j=0;j<h.markers.length;j++){h.markers[j].setVisible(true)}};this.debugHideMarkers=function(){for(var j=0;j<h.markers.length;j++){h.markers[j].setVisible(false)}};this.getMarkerCount=function(){return this.markers.length};this.contains=function(j){return h.bounds.contains(j)};this.getPosition=function(){return this.center};this.getBounds=function(){return this.bounds};this.getMarkerBounds=function(){var k=new google.maps.LatLngBounds(h.markers[0].getPosition(),h.markers[0].getPosition());for(var j=1;j<h.markers.length;j++){k.extend(h.markers[j].getPosition())}return k};this.addMarker(i)}function Fluster2ClusterMarker(b,d){this.fluster=b;this.cluster=d;this.position=this.cluster.getPosition();this.markerCount=this.cluster.getMarkerCount();this.map=this.fluster.getMap();this.style=null;this.div=null;var c=this.fluster.getStyles();for(var a in c){if(this.markerCount>a){this.style=c[a]}else{break}}google.maps.OverlayView.call(this);this.setMap(this.map);this.draw()}Fluster2ClusterMarker.prototype=new google.maps.OverlayView();Fluster2ClusterMarker.prototype.draw=function(){if(this.div==null){var b=this;this.div=document.createElement("div");this.div.style.position="absolute";this.div.style.width=this.style.width+"px";this.div.style.height=this.style.height+"px";this.div.style.lineHeight=this.style.height+"px";this.div.style.background='transparent url("'+this.style.image+'") 50% 50% no-repeat';this.div.style.color=this.style.textColor;this.div.style.textAlign="center";this.div.style.fontFamily="Arial, Helvetica";this.div.style.fontSize="11px";this.div.style.fontWeight="bold";this.div.innerHTML=this.markerCount;this.div.style.cursor="pointer";google.maps.event.addDomListener(this.div,"click",function(){b.map.fitBounds(b.cluster.getMarkerBounds())});this.getPanes().overlayLayer.appendChild(this.div)}var a=this.getProjection().fromLatLngToDivPixel(this.position);this.div.style.left=(a.x-parseInt(this.style.width/2))+"px";this.div.style.top=(a.y-parseInt(this.style.height/2))+"px"};Fluster2ClusterMarker.prototype.hide=function(){this.div.style.display="none"};Fluster2ClusterMarker.prototype.show=function(){this.div.style.display="block"};function Fluster2ProjectionOverlay(a){google.maps.OverlayView.call(this);this.setMap(a);this.getP=function(){return this.getProjection()}}Fluster2ProjectionOverlay.prototype=new google.maps.OverlayView();Fluster2ProjectionOverlay.prototype.draw=function(){};function Fluster2(e,c){var a=e;var f=new Fluster2ProjectionOverlay(a);var g=this;var h=new Object();var k=new Object();var d=false;this.debugEnabled=c;this.gridSize=60;this.markers=new Array();this.currentZoomLevel=-1;this.styles={0:{image:"http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m1.png",textColor:"#FFFFFF",width:53,height:52},10:{image:"http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m2.png",textColor:"#FFFFFF",width:56,height:55},20:{image:"http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m3.png",textColor:"#FFFFFF",width:66,height:65}};var b=null;function j(){var u=a.getZoom();if(h[u]){g.debug("Clusters for zoom level "+u+" already initialized.")}else{var t=new Array();var q=0;var r=g.markers.length;for(var n=0;n<r;n++){var p=g.markers[n];var o=p.getPosition();var m=false;for(var l=q-1;l>=0;l--){var s=t[l];if(s.contains(o)){s.addMarker(p);m=true;break}}if(!m){var s=new Fluster2Cluster(g,p);t.push(s);q++}}h[u]=t;g.debug("Initialized "+h[u].length+" clusters for zoom level "+u+".")}if(h[g.currentZoomLevel]){for(var n=0;n<h[g.currentZoomLevel].length;n++){h[g.currentZoomLevel][n].hide()}}g.currentZoomLevel=u;i()}function i(){var m=a.getBounds();for(var n=0;n<h[g.currentZoomLevel].length;n++){var l=h[g.currentZoomLevel][n];if(m.contains(l.getPosition())){l.show()}}}this.zoomChanged=function(){window.clearInterval(b);b=window.setTimeout(j,500)};this.getMap=function(){return a};this.getProjection=function(){return f.getP()};this.debug=function(l){if(g.debugEnabled){console.log("Fluster2: "+l)}};this.addMarker=function(l){g.markers.push(l)};this.getStyles=function(){return g.styles};this.initialize=function(){if(!this.listenersAdded){this.listenersAdded=true;google.maps.event.addListener(a,"zoom_changed",this.zoomChanged);google.maps.event.addListener(a,"dragend",i)}window.setTimeout(j,1000)};this.clearMarkers=function(){for(var m=0;m<15;m++){for(var l=0;h[m]&&l<h[m].length;l++){if(h[m][l].marker){h[m][l].marker.setMap(null);h[m][l].hide();h[m][l]=null}}h[m]=null}for(m=0;m<g.markers.length;m++){g.markers[m].setMap(null)}g.markers=new Array();h=new Object()}};
