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