Clusterer=function(a){this.map=a;this.markers=[];this.clusters=[];this.timeout=null;this.currentZoomLevel=a.getZoom();this.maxVisibleMarkers=Clusterer.defaultMaxVisibleMarkers;this.gridSize=Clusterer.defaultGridSize;this.minMarkersPerCluster=Clusterer.defaultMinMarkersPerCluster;this.maxLinesPerInfoBox=Clusterer.defaultMaxLinesPerInfoBox;this.icon=Clusterer.defaultIcon;GEvent.addListener(a,'zoomend',Clusterer.MakeCaller(Clusterer.Display,this));GEvent.addListener(a,'moveend',Clusterer.MakeCaller(Clusterer.Display,this));GEvent.addListener(a,'infowindowclose',Clusterer.MakeCaller(Clusterer.PopDown,this))};Clusterer.defaultMaxVisibleMarkers=150;Clusterer.defaultGridSize=24;Clusterer.defaultMinMarkersPerCluster=5;Clusterer.defaultMaxLinesPerInfoBox=10;Clusterer.defaultIcon=new GIcon();Clusterer.defaultIcon.image='/images/elements/blue2.png';Clusterer.defaultIcon.shadow='/images/elements/shadow.png';Clusterer.defaultIcon.iconSize=new GSize(20,34);Clusterer.defaultIcon.shadowSize=new GSize(37,34);Clusterer.defaultIcon.iconAnchor=new GPoint(13,34);Clusterer.defaultIcon.infoWindowAnchor=new GPoint(13,3);Clusterer.defaultIcon.infoShadowAnchor=new GPoint(27,37);Clusterer.prototype.SetIcon=function(a){this.icon=a};Clusterer.prototype.SetMaxVisibleMarkers=function(n){this.maxVisibleMarkers=n};Clusterer.prototype.SetMinMarkersPerCluster=function(n){this.minMarkersPerCluster=n};Clusterer.prototype.SetMaxLinesPerInfoBox=function(n){this.maxLinesPerInfoBox=n};Clusterer.prototype.AddMarker=function(a,b){if(a.setMap!=null)a.setMap(this.map);a.title=b;a.onMap=false;this.markers.push(a);this.DisplayLater()};Clusterer.prototype.RemoveMarker=function(a){for(var i=0;i<this.markers.length;++i)if(this.markers[i]==a){if(a.onMap)this.map.removeOverlay(a);for(var j=0;j<this.clusters.length;++j){var b=this.clusters[j];if(b!=null){for(var k=0;k<b.markers.length;++k)if(b.markers[k]==a){b.markers[k]=null;--b.markerCount;break}if(b.markerCount==0){this.ClearCluster(b);this.clusters[j]=null}else if(b==this.poppedUpCluster)Clusterer.RePop(this)}}this.markers[i]=null;break}this.DisplayLater()};Clusterer.prototype.DisplayLater=function(){if(this.timeout!=null)clearTimeout(this.timeout);this.timeout=setTimeout(Clusterer.MakeCaller(Clusterer.Display,this),50)};Clusterer.Display=function(a){var i,j,marker,cluster;clearTimeout(a.timeout);var b=a.map.getZoom();if(b!=a.currentZoomLevel){for(i=0;i<a.clusters.length;++i)if(a.clusters[i]!=null){a.ClearCluster(a.clusters[i]);a.clusters[i]=null}a.clusters.length=0;a.currentZoomLevel=b}var c=a.map.getBounds();var d=c.getSouthWest();var e=c.getNorthEast();var f=e.lng()-d.lng();var g=e.lat()-d.lat();if(f<300&&g<150){f*=0.10;g*=0.10;c=new GLatLngBounds(new GLatLng(d.lat()-g,d.lng()-f),new GLatLng(e.lat()+g,e.lng()+f))}var h=[];var k=[];for(i=0;i<a.markers.length;++i){marker=a.markers[i];if(marker!=null)if(c.contains(marker.getPoint()))h.push(marker);else h.push(marker)}for(i=0;i<k.length;++i){marker=k[i];if(marker.onMap){a.map.removeOverlay(marker);marker.onMap=false}}for(i=0;i<a.clusters.length;++i){cluster=a.clusters[i];if(cluster!=null&&!c.contains(cluster.marker.getPoint())&&cluster.onMap){a.map.removeOverlay(cluster.marker);cluster.onMap=false}}if(h.length>a.maxVisibleMarkers){var l=c.getNorthEast().lat()-c.getSouthWest().lat();var m=l/a.gridSize;var n=m/Math.cos((c.getNorthEast().lat()+c.getSouthWest().lat())/2.0*Math.PI/180.0);for(var o=c.getSouthWest().lat();o<=c.getNorthEast().lat();o+=m)for(var p=c.getSouthWest().lng();p<=c.getNorthEast().lng();p+=n){cluster=new Object();cluster.clusterer=a;cluster.bounds=new GLatLngBounds(new GLatLng(o,p),new GLatLng(o+m,p+n));cluster.markers=[];cluster.markerCount=0;cluster.onMap=false;cluster.marker=null;a.clusters.push(cluster)}for(i=0;i<h.length;++i){marker=h[i];if(marker!=null&&!marker.inCluster){for(j=0;j<a.clusters.length;++j){cluster=a.clusters[j];if(cluster!=null&&cluster.bounds.contains(marker.getPoint())){cluster.markers.push(marker);++cluster.markerCount;marker.inCluster=true}}}}for(i=0;i<a.clusters.length;++i)if(a.clusters[i]!=null&&a.clusters[i].markerCount<a.minMarkersPerCluster){a.ClearCluster(a.clusters[i]);a.clusters[i]=null}for(i=a.clusters.length-1;i>=0;--i)if(a.clusters[i]!=null)break;else--a.clusters.length;for(i=0;i<a.clusters.length;++i){cluster=a.clusters[i];if(cluster!=null){for(j=0;j<cluster.markers.length;++j){marker=cluster.markers[j];if(marker!=null&&marker.onMap){a.map.removeOverlay(marker);marker.onMap=false}}}}for(i=0;i<a.clusters.length;++i){cluster=a.clusters[i];if(cluster!=null&&cluster.marker==null){var q=0.0,yTotal=0.0;for(j=0;j<cluster.markers.length;++j){marker=cluster.markers[j];if(marker!=null){q+=(+marker.getPoint().lng());yTotal+=(+marker.getPoint().lat())}}var r=new GLatLng(yTotal/cluster.markerCount,q/cluster.markerCount);marker=new GMarker(r,{icon:a.icon});cluster.marker=marker;GEvent.addListener(marker,'click',Clusterer.MakeCaller(Clusterer.PopUp,cluster))}}}for(i=0;i<h.length;++i){marker=h[i];if(marker!=null&&!marker.onMap&&!marker.inCluster){a.map.addOverlay(marker);if(marker.addedToMap!=null)marker.addedToMap();marker.onMap=true}}for(i=0;i<a.clusters.length;++i){cluster=a.clusters[i];if(cluster!=null&&!cluster.onMap&&c.contains(cluster.marker.getPoint())){a.map.addOverlay(cluster.marker);cluster.onMap=true}}Clusterer.RePop(a)};Clusterer.PopUp=function(a){var b=a.clusterer;var c=createElement('ul');c.className='checkbox';var d;var n=0;for(var i=0;i<a.markers.length;++i){var e=a.markers[i];if(e!=null){++n;d=createElement('li');d.appendChild(e.content);c.appendChild(d);if(n==b.maxLinesPerInfoBox-1&&a.markerCount>b.maxLinesPerInfoBox){d=createElement('li');d.appendChild(createElement('text','...and '+(a.markerCount-n)+' more'));c.appendChild(d);break}}}b.map.closeInfoWindow();a.marker.openInfoWindow(c);b.poppedUpCluster=a};Clusterer.RePop=function(a){if(a.poppedUpCluster!=null)Clusterer.PopUp(a.poppedUpCluster)};Clusterer.PopDown=function(a){a.poppedUpCluster=null};Clusterer.prototype.ClearCluster=function(a){var i,marker;for(i=0;i<a.markers.length;++i)if(a.markers[i]!=null){a.markers[i].inCluster=false;a.markers[i]=null}a.markers.length=0;a.markerCount=0;if(a==this.poppedUpCluster)this.map.closeInfoWindow();if(a.onMap){this.map.removeOverlay(a.marker);a.onMap=false}};Clusterer.MakeCaller=function(a,b){return function(){a(b)}};GMarker.prototype.setMap=function(a){this.map=a};GMarker.prototype.addedToMap=function(){this.map=null};GMarker.prototype.origBindInfoWindow=GMarker.prototype.bindInfoWindow;GMarker.prototype.bindInfoWindow=function(a,b){this.content=a;return this.origBindInfoWindow(a,b)};GMarker.prototype.origOpenInfoWindow=GMarker.prototype.openInfoWindow;GMarker.prototype.openInfoWindow=function(a,b){if(this.map!=null)return this.map.openInfoWindow(this.getPoint(),a,b);else return this.origOpenInfoWindow(a,b)};GMarker.prototype.origOpenInfoWindowHtml=GMarker.prototype.openInfoWindowHtml;GMarker.prototype.openInfoWindowHtml=function(a,b){if(this.map!=null)return this.map.openInfoWindowHtml(this.getPoint(),a,b);else return this.origOpenInfoWindowHtml(a,b)};GMarker.prototype.origOpenInfoWindowTabs=GMarker.prototype.openInfoWindowTabs;GMarker.prototype.openInfoWindowTabs=function(a,b){if(this.map!=null)return this.map.openInfoWindowTabs(this.getPoint(),a,b);else return this.origOpenInfoWindowTabs(a,b)};GMarker.prototype.origOpenInfoWindowTabsHtml=GMarker.prototype.openInfoWindowTabsHtml;GMarker.prototype.openInfoWindowTabsHtml=function(a,b){if(this.map!=null)return this.map.openInfoWindowTabsHtml(this.getPoint(),a,b);else return this.origOpenInfoWindowTabsHtml(a,b)};GMarker.prototype.origShowMapBlowup=GMarker.prototype.showMapBlowup;GMarker.prototype.showMapBlowup=function(a){if(this.map!=null)return this.map.showMapBlowup(this.getPoint(),a);else return this.origShowMapBlowup(a)};