function ClusterMarker(b,a){this.type=G_NORMAL_MAP;this.enumType={norm:G_NORMAL_MAP,sat:G_SATELLITE_MAP,hy:G_HYBRID_MAP,tr:G_PHYSICAL_MAP};this._cats=[];this.lines=new Hash();this.map=b;this._mapMarkerIds={};this._mapMarkers=[];this._iconBounds=[];this.photoIcons={};this.cachePhotoIcon=null;this._iconCache={};this.clusterCount=0;this._clusterMarkers=[];this._eventListeners=[];if(typeof(a)==="undefined"){a={}}this.borderPadding=256;this.clusteringEnabled=(a.clusteringEnabled===false)?false:true;if(a.clusterMarkerClick){this.clusterMarkerClick=a.clusterMarkerClick}this.clusterMarkerIconCache=[];this.clusterMarkerTitle=(a.clusterMarkerTitle)?a.clusterMarkerTitle:"%count oplevelser";if(a.fitMapMaxZoom){this.fitMapMaxZoom=a.fitMapMaxZoom}this.intersectPadding=1;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(a){var b;var c=[];for(b=a.length-1;b>=0;b--){if(!this._mapMarkerIds[a[b].id]){c.push(a[b])}else{if(!this._mapMarkerIds[a[b].id]._isVisible){this._mapMarkerIds[a[b].id]._isActive=false;this._mapMarkerIds[a[b].id]._makeVisible=false;this._mapMarkerIds[a[b].id]._remove=false}}}for(b=c.length-1;b>=0;b--){c[b]._isVisible=false;c[b]._isActive=false;c[b]._makeVisible=false;c[b]._remove=false;this._mapMarkerIds[c[b].id]=c[b]}if(c.length>0){this._mapMarkers=this._mapMarkers.concat(c)}};ClusterMarker.prototype._clusterMarker=function(f){var j="z"+(++this.clusterCount);var c="/extension/gmaplocation/design/standard/images/markers2/zooms/";function p(t,i){return new GMarker(t,{icon:i})}var k=new GLatLngBounds(),m,l,a=[],h,e=this,b=this._mapMarkers;for(m=f.length-1;m>=0;m--){h=b[f[m]];h.index=f[m];k.extend(h.getLatLng());a.push(h)}var o=c+"bk.png";var s=new Image();s.src=c+f.length+".png";var r=new Image();r.src=c+f.length+"ov.png";var q=new Image();q.src=o;l=p(k.getCenter(),this.clusterMarkerIcon(f.length));l.clusterGroupBounds=k;l.id=j;var n=this;var g=GEvent.addListener(l,"mouseover",function(){this.setImage(c+f.length+"ov.png");this.origZ=GOverlay.getZIndex(this.getPoint().lat());var i=$("mtgt_"+this.id);i.style.zIndex=1000;var t=new Element("span",{id:"newDiv",style:"background-repeat: no-repeat; background-position: center right; background-image: url("+o+"); font-family: Arial; white-space: nowrap;font-size: 11px; color:#6c6c6c;height:23px; padding: 7px 15px 0 0;position: absolute; z-index: 1000; top:"+(parseInt(i.style.top)+3)+"px; left:"+(parseInt(i.style.left)+26)+"px"}).update("oplevelser");i.parentNode.appendChild(t)});this._eventListeners.push(g);var d=GEvent.addListener(l,"mouseout",function(){this.setImage(c+f.length+".png");$("mtgt_"+this.id).style.zIndex=this.origZ;while($("newDiv")){$("newDiv").remove()}});this._eventListeners.push(d);this._eventListeners.push(GEvent.addListener(l,"click",function(){GEvent.removeListener(g);GEvent.removeListener(d);while($("newDiv")){$("newDiv").remove()}e.clusterMarkerClick({clusterMarker:l,clusteredMarkers:a})}));l._childIndexes=f;for(m=f.length-1;m>=0;m--){b[f[m]]._parentCluster=l}return l};ClusterMarker.prototype.clusterMarkerClick=function(a){if(this.poiShowing){hidePoi(0)}if(this.lastClick){this.clearLastClickIcon()}this.map.setCenter(a.clusterMarker.getLatLng(),this.map.getCurrentMapType().getBoundsZoomLevel(a.clusterMarker.clusterGroupBounds,new GSize(this.map.getSize().width-400,this.map.getSize().height-80)))};ClusterMarker.prototype.clusterMarkerIcon=function(a){var c="/extension/gmaplocation/design/standard/images/markers2/zooms/";if(this.clusterMarkerIconCache[a]){return this.clusterMarkerIconCache[a]}else{var b=new GIcon();b.iconSize=new GSize(26,31);b.iconAnchor=new GPoint(14,17);b.image=c+a+".png";this.clusterMarkerIconCache[a]=b;return b}};ClusterMarker.prototype._filterActiveMapMarkers=function(){var k=this.borderPadding,j=this.map.getZoom(),q=this.map.getCurrentMapType().getProjection(),o,c,m,h,n,d,b=this.map.getBounds(),f,p,e=[],l,a=this._mapMarkers,g=this._iconBounds;if(k){o=q.fromLatLngToPixel(b.getSouthWest(),j);c=new GPoint(o.x-k,o.y+k);m=q.fromPixelToLatLng(c,j);h=q.fromLatLngToPixel(b.getNorthEast(),j);n=new GPoint(h.x+k,h.y-k);d=q.fromPixelToLatLng(n,j);b.extend(m);b.extend(d)}this._activeMarkersChanged=false;if(typeof(g[j])==="undefined"){this._iconBounds[j]=[];this._activeMarkersChanged=true;for(f=a.length-1;f>=0;f--){p=a[f];p._isActive=b.containsLatLng(p.getLatLng())?true:false;p._makeVisible=p._isActive&&!p._remove;if(p._isActive){e.push(f)}}}else{for(f=a.length-1;f>=0;f--){p=a[f];l=p._isActive;p._isActive=b.containsLatLng(p.getLatLng())?true:false;p._makeVisible=p._isActive&&!p._remove;if(!this._activeMarkersChanged&&l!==p._isActive){this._activeMarkersChanged=true}if(p._isActive&&typeof(g[j][f])==="undefined"){e.push(f)}}}return e};ClusterMarker.prototype._filterIntersectingMapMarkers=function(){var e,d,b,a=this.map.getZoom(),f=this._mapMarkers,c=this._iconBounds;for(d=f.length-1;d>0;d--){if(f[d]._makeVisible){e=[];for(b=d-1;b>=0;b--){if(f[b]._makeVisible&&!c[a][d]._noCluster&&!c[a][b]._noCluster&&c[a][d].bounds.intersects(c[a][b].bounds)){e.push(b)}}if(e.length!==0){e.push(d);for(b=e.length-1;b>=0;b--){f[e[b]]._makeVisible=false}this._clusterMarkers.push(this._clusterMarker(e))}}}};ClusterMarker.prototype.fitMapToMarkers=function(){var d=this._mapMarkers,c=new GLatLngBounds(),b;for(b=d.length-1;b>=0;b--){c.extend(d[b].getLatLng())}var a=this.map.getBoundsZoomLevel(c);if(this.fitMapMaxZoom&&a>this.fitMapMaxZoom){a=this.fitMapMaxZoom}this.map.setCenter(c.getCenter(),a);this.refresh()};ClusterMarker.prototype._mapTypeChanged=function(){this.refresh(true)};ClusterMarker.prototype._moveEnd=function(){if(!this._cancelMoveEnd){this.refresh()}else{this._cancelMoveEnd=false}};ClusterMarker.prototype._preCacheIconBounds=function(c,h){var n=this.map.getCurrentMapType().getProjection(),g,o,e,a,j,l,f,k,d,m=this.intersectPadding,b=this._mapMarkers;for(g=c.length-1;g>=0;g--){o=b[c[g]];e=o.getIcon().iconSize;a=n.fromLatLngToPixel(o.getLatLng(),h);j=o.getIcon().iconAnchor;l=new GPoint(a.x-j.x-m,a.y-j.y+e.height+m);f=new GPoint(a.x-j.x+e.width+m,a.y-j.y-m);k=n.fromPixelToLatLng(l,h);d=n.fromPixelToLatLng(f,h);this._iconBounds[h][c[g]]={bounds:new GLatLngBounds(k,d),_noCluster:o._noCluster}}};ClusterMarker.prototype.refresh=function(d){var c,b,e=this.map.getZoom(),a=this._filterActiveMapMarkers();if(this._activeMarkersChanged||d){this._removeClusterMarkers();if(this.clusteringEnabled&&e<this.map.getCurrentMapType().getMaximumResolution()){if(a.length>0){this._preCacheIconBounds(a,e)}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}}this.drawLines()}};ClusterMarker.prototype._removeClusterMarkers=function(){var d,b,g=this.map,a=this._eventListeners,f=this._clusterMarkers,c,e=this._mapMarkers;for(d=f.length-1;d>=0;d--){c=f[d]._childIndexes;for(b=c.length-1;b>=0;b--){delete e[c[b]]._parentCluster}g.removeOverlay(f[d])}for(d=a.length-1;d>=0;d--){GEvent.removeListener(a[d])}this._clusterMarkers=[];this._eventListeners=[]};ClusterMarker.prototype.removeMarkers=function(){var a,b=this._mapMarkers,c=this.map;for(a=b.length-1;a>=0;a--){if(b[a]._isVisible){c.removeOverlay(b[a])}delete b[a]._isVisible;delete b[a]._isActive;delete b[a]._makeVisible}this._removeClusterMarkers();this._mapMarkers=[];this._iconBounds=[]};ClusterMarker.prototype.triggerClick=function(h){var k=this._mapMarkers[h];if(k._isVisible){GEvent.trigger(k,"click")}else{if(k._isActive){var f=k._parentCluster._childIndexes,b=true,c,d,g=this.map.getZoom(),j,e=this._iconBounds,a=this.map.getCurrentMapType().getMaximumResolution();while(b&&g<a){b=false;g++;if(typeof(e[g])==="undefined"){e[g]=[];this._preCacheIconBounds(f,g)}else{c=[];for(d=f.length-1;d>=0;d--){if(typeof(e[g][f[d]].bounds)==="undefined"){c.push(f[d])}}if(c.length>=1){this._preCacheIconBounds(c,g)}}for(d=f.length-1;d>=0;d--){j=f[d];if(j!==h&&e[g][j].intersects(e[g][h].bounds)){b=true;break}}}this.map.setCenter(k.getLatLng(),g);this.triggerClick(h)}else{this.map.setCenter(k.getLatLng());this.triggerClick(h)}}};ClusterMarker.prototype._zoomEnd=function(){this._cancelMoveEnd=true;this.refresh(true)};ClusterMarker.prototype._inCat=function(a,b){var c;for(c=a.length-1;c>=0;c--){if(this._cats.indexOf(a[c])>-1){return true}}return false};ClusterMarker.prototype._removeCat=function(b){var d,a=[],e=0,f=this._mapMarkers,g=this;var c=this._cats.indexOf(b);if(c>-1){this._cats.splice(c,1)}this.lines.each(function(h){if(h.value.line[1]==b){g.map.removeOverlay(h.value.poly);g.lines.unset(h.key)}});for(d=f.length-1;d>=0;d--){if(!f[d]._remove&&f[d].cat.indexOf(b)>-1&&(f[d].cat.length==1||!this._inCat(f[d].cat,b))){e=1;f[d]._makeVisible=false;f[d]._remove=true}else{}}if(e){this.refresh(1)}};ClusterMarker.prototype.changeType=function(b){if(!!this.enumType[b]){if(this.type!=this.enumType[b]){this.type=this.enumType[b];this.map.setMapType(this.type);var a=$(b);a=a.ancestors()[0];a.siblings().each(function(c){c.removeClassName("active")});a.addClassName("active")}}};ClusterMarker.prototype.resetZoom=function(){hidePoi(0);this.map.setCenter(new GLatLng(this.lat,this.lng),this.zoom)};ClusterMarker.prototype.clearLastClickIcon=function(){try{if(this.lastClick){this.lastClick.setImage(this.lastBk);this.lastClick.clicked=false}}catch(a){}};ClusterMarker.prototype.addLines=function(b){var d=this;var a;var c;b.each(function(f){var e=f[0].inspect();if(!d.lines.get(e)){d.lines.set(e,{line:f,p:{},pop:0,draw:0})}})};ClusterMarker.prototype.drawLines=function(){var b=this;var a;this.lines.each(function(c){b1=false;if(!c.value.draw){if(!c.value.pop){if(!b.populateLine(c.value)){return}c.value.pop=1;a=[];c.value.line[0].each(function(d){a.push(new GLatLng(c.value.p[d].lat(),c.value.p[d].lng()))});c.value.poly=new GPolyline(a,c.value.line[2],c.value.line[3],c.value.line[4],{geodesic:true,clickable:false})}b.map.addOverlay(c.value.poly);c.value.draw=1}else{if(c.value.draw==1){}}})};ClusterMarker.prototype.populateLine=function(b){var c;var a=b.line[0];for(c=a.length-1;c>-1;c--){if(!!this._mapMarkerIds[a[c]]&&!b.p[a[c]]){b.p[a[c]]=this._mapMarkerIds[a[c]].getPoint()}}return a.length==$H(b.p).keys().length};ClusterMarker.prototype.addPhoto=function(g,f,d){var c="/extension/gmaplocation/design/standard/images/markers2/";$("map").scrollTo();this.map.panTo(new GLatLng(g[0],g[1]));var e=this;if(!!this.photoIcons[f]){return}var b;if(this.cachePhotoIcon){b=this.cachePhotoIcon}else{b=new GIcon();b.iconSize=new GSize(26,40);b.iconAnchor=new GPoint(15,36);b.image=c+"photo.png";this.cachePhotoIcon=b}var a=new GMarker(new GLatLng(g[0],g[1]),{icon:b});a.id=f;this.photoIcons[f]=a;GEvent.addListener(a,"mouseover",function(){this.mOv=true;this.setImage(c+"photoov.png");this.origZ=GOverlay.getZIndex(this.getPoint().lat());var h=$("mtgt_"+f);h.style.zIndex=100;var i=new Element("span",{id:"newDiv",style:"background-repeat: no-repeat; background-position: center right; background-image: url("+c+"photobk.png); font-family: Arial; white-space: nowrap;font-size: 11px; color:#777;height:23px; padding: 7px 15px 0 3px;position: absolute; z-index: 100; top:"+(parseInt(h.style.top))+"px; left:"+(parseInt(h.style.left)+26)+"px"}).update(d);h.parentNode.appendChild(i)});GEvent.addListener(a,"mouseout",function(){this.mOv=false;this.setImage(c+"photoov.png");$("mtgt_"+this.id).style.zIndex=this.origZ;while($("newDiv")){$("newDiv").remove()}});this.map.addOverlay(a)};