function MarkerClusterer(b,g,a){var l=[];var m=b;var e=null;var j=this;var f=60;var q=[53,56,66,78,90];var d=[];var c=[];var k=null;var h=0;for(h=1;h<=5;++h){d.push({url:"http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/images/m"+h+".png",height:q[h-1],width:q[h-1]})}if(typeof a==="object"&&a!==null){if(typeof a.gridSize==="number"&&a.gridSize>0){f=a.gridSize}if(typeof a.maxZoom==="number"){e=a.maxZoom}if(typeof a.styles==="object"&&a.styles!==null&&a.styles.length!==0){d=a.styles}}function n(){if(c.length===0){return}var i=[];for(h=0;h<c.length;++h){j.addMarker(c[h],true,null,null,true)}c=i}this.getStyles_=function(){return d};this.clearMarkers=function(){for(var r=0;r<l.length;++r){if(typeof l[r]!=="undefined"&&l[r]!==null){l[r].clearMarkers()}}l=[];c=[];GEvent.removeListener(k)};function p(i){return m.getBounds().containsLatLng(i.getLatLng())}function o(u){var r=u.length;var t=[];for(var s=r-1;s>=0;--s){j.addMarker(u[s].marker,true,u[s].isAdded,t,true)}n()}this.addMarker=function(w,t,B,u,C){if(C!==true){if(!p(w)){c.push(w);return}}var x=B;var z=u;var y=m.fromLatLngToDivPixel(w.getLatLng());if(typeof x!=="boolean"){x=false}if(typeof z!=="object"||z===null){z=l}var s=z.length;var A=null;for(var v=s-1;v>=0;v--){A=z[v];var r=A.getCenter();if(r===null){continue}r=m.fromLatLngToDivPixel(r);if(y.x>=r.x-f&&y.x<=r.x+f&&y.y>=r.y-f&&y.y<=r.y+f){A.addMarker({isAdded:x,marker:w});if(!t){A.redraw_()}return}}A=new Cluster(this,b);A.addMarker({isAdded:x,marker:w});if(!t){A.redraw_()}z.push(A);if(z!==l){l.push(A)}};this.removeMarker=function(r){for(var s=0;s<l.length;++s){if(l[s].remove(r)){l[s].redraw_();return}}};this.redraw_=function(){var s=this.getClustersInViewport_();for(var r=0;r<s.length;++r){s[r].redraw_(true)}};this.getClustersInViewport_=function(){var t=[];var s=m.getBounds();for(var r=0;r<l.length;r++){if(l[r].isInBounds(s)){t.push(l[r])}}return t};this.getMaxZoom_=function(){return e};this.getMap_=function(){return m};this.getGridSize_=function(){return f};this.getTotalMarkers=function(){var r=0;for(var s=0;s<l.length;++s){r+=l[s].getTotalMarkers()}return r};this.getTotalClusters=function(){return l.length};this.resetViewport=function(){var x=this.getClustersInViewport_();var w=[];var v=0;for(var s=0;s<x.length;++s){var y=x[s];var z=y.getCurrentZoom();if(z===null){continue}var A=m.getZoom();if(A!==z){var t=y.getMarkers();for(var r=0;r<t.length;++r){var u={isAdded:false,marker:t[r].marker};w.push(u)}y.clearMarkers();v++;for(r=0;r<l.length;++r){if(y===l[r]){l.splice(r,1)}}}}o(w);this.redraw_()};this.addMarkers=function(s){for(var r=0;r<s.length;++r){this.addMarker(s[r],true)}this.redraw_()};if(typeof g==="object"&&g!==null){this.addMarkers(g)}k=GEvent.addListener(m,"moveend",function(){j.resetViewport()})}function Cluster(c){var b=null;var g=[];var e=c;var f=c.getMap_();var d=null;var a=f.getZoom();this.getMarkers=function(){return g};this.isInBounds=function(l){if(b===null){return false}if(!l){l=f.getBounds()}var h=f.fromLatLngToDivPixel(l.getSouthWest());var n=f.fromLatLngToDivPixel(l.getNorthEast());var m=f.fromLatLngToDivPixel(b);var j=true;var i=c.getGridSize_();if(a!==f.getZoom()){var k=f.getZoom()-a;i=Math.pow(2,k)*i}if(n.x!==h.x&&(m.x+i<h.x||m.x-i>n.x)){j=false}if(j&&(m.y+i<n.y||m.y-i>h.y)){j=false}return j};this.getCenter=function(){return b};this.addMarker=function(h){if(b===null){b=h.marker.getLatLng()}g.push(h)};this.removeMarker=function(h){for(var j=0;j<g.length;++j){if(h===g[j].marker){if(g[j].isAdded){f.removeOverlay(g[j].marker)}g.splice(j,1);return true}}return false};this.getCurrentZoom=function(){return a};this.redraw_=function(k){if(!k&&!this.isInBounds()){return}a=f.getZoom();var h=0;var j=c.getMaxZoom_();if(j===null){j=f.getCurrentMapType().getMaximumResolution()}if(a>=j||this.getTotalMarkers()===1){for(h=0;h<g.length;++h){if(g[h].isAdded){if(g[h].marker.isHidden()){g[h].marker.show()}}else{f.addOverlay(g[h].marker);g[h].isAdded=true}}if(d!==null){d.hide()}}else{for(h=0;h<g.length;++h){if(g[h].isAdded&&(!g[h].marker.isHidden())){g[h].marker.hide()}}if(d===null){d=new ClusterMarker_(b,this.getTotalMarkers(),e.getStyles_(),e.getGridSize_());f.addOverlay(d)}else{if(d.isHidden()){d.show()}d.redraw(true)}}};this.clearMarkers=function(){if(d!==null){f.removeOverlay(d)}for(var h=0;h<g.length;++h){if(g[h].isAdded){f.removeOverlay(g[h].marker)}}g=[]};this.getTotalMarkers=function(){return g.length}}function ClusterMarker_(f,d,c,e){var a=0;var b=d;while(b!==0){b=parseInt(b/10,10);a++}if(c.length<a){a=c.length}this.url_=c[a-1].url;this.height_=c[a-1].height;this.width_=c[a-1].width;this.textColor_=c[a-1].opt_textColor;this.anchor_=c[a-1].opt_anchor;this.latlng_=f;this.index_=a;this.styles_=c;this.text_=d;this.padding_=e}ClusterMarker_.prototype=new GOverlay();ClusterMarker_.prototype.initialize=function(d){this.map_=d;var g=document.createElement("div");var f=this.latlng_;var e=d.fromLatLngToDivPixel(f);e.x-=parseInt(this.width_/2,10);e.y-=parseInt(this.height_/2,10);var c="";if(document.all){c='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="'+this.url_+'");'}else{c="background:url("+this.url_+");"}if(typeof this.anchor_==="object"){if(typeof this.anchor_[0]==="number"&&this.anchor_[0]>0&&this.anchor_[0]<this.height_){c+="height:"+(this.height_-this.anchor_[0])+"px;padding-top:"+this.anchor_[0]+"px;"}else{c+="height:"+this.height_+"px;line-height:"+this.height_+"px;"}if(typeof this.anchor_[1]==="number"&&this.anchor_[1]>0&&this.anchor_[1]<this.width_){c+="width:"+(this.width_-this.anchor_[1])+"px;padding-left:"+this.anchor_[1]+"px;"}else{c+="width:"+this.width_+"px;text-align:center;"}}else{c+="height:"+this.height_+"px;line-height:"+this.height_+"px;";c+="width:"+this.width_+"px;text-align:center;"}var a=this.textColor_?this.textColor_:"black";g.style.cssText=c+"cursor:pointer;top:"+e.y+"px;left:"+e.x+"px;color:"+a+";position:absolute;font-size:11px;font-family:Arial,sans-serif;font-weight:bold";g.innerHTML=this.text_;d.getPane(G_MAP_MAP_PANE).appendChild(g);var b=this.padding_;GEvent.addDomListener(g,"click",function(){var k=d.fromLatLngToDivPixel(f);var h=new GPoint(k.x-b,k.y+b);h=d.fromDivPixelToLatLng(h);var j=new GPoint(k.x+b,k.y-b);j=d.fromDivPixelToLatLng(j);var i=d.getBoundsZoomLevel(new GLatLngBounds(h,j),d.getSize());d.setCenter(f,i)});this.div_=g};ClusterMarker_.prototype.remove=function(){this.div_.parentNode.removeChild(this.div_)};ClusterMarker_.prototype.copy=function(){return new ClusterMarker_(this.latlng_,this.index_,this.text_,this.styles_,this.padding_)};ClusterMarker_.prototype.redraw=function(a){if(!a){return}var b=this.map_.fromLatLngToDivPixel(this.latlng_);b.x-=parseInt(this.width_/2,10);b.y-=parseInt(this.height_/2,10);this.div_.style.top=b.y+"px";this.div_.style.left=b.x+"px"};ClusterMarker_.prototype.hide=function(){this.div_.style.display="none"};ClusterMarker_.prototype.show=function(){this.div_.style.display=""};ClusterMarker_.prototype.isHidden=function(){return this.div_.style.display==="none"};
