﻿var BubbleCluster=Class.create();Object.extend(BubbleCluster.prototype,{Id:null,Icon:null,Latitude:null,Longitude:null,Items:null,initialize:function(aP,bf,aC,aD,aH){this.Id=aP;this.Icon=bf;this.Latitude=aC;this.Longitude=aD;this.Items=aH;}});var BubbleItem=Class.create();Object.extend(BubbleItem.prototype,{Id:null,Icon:null,Location:null,UtmNorthing:null,UtmEasting:null,Latitude:null,Longitude:null,Title:null,Logo:null,Subtitles:null,LookupParameters:null,ShowCoordinates:true,initialize:function(aP,bf,aS,xt,tG,xG,tn,ue,sO,fX,xA){this.Id=aP;this.Icon=bf;this.Title=aS;this.Logo=xt;this.Subtitles=tG;this.LookupParameters=xG;this.UtmNorthing=ue;this.UtmEasting=sO;this.Latitude=fX;this.Longitude=xA;this.ShowCoordinates=tn;}});var BubbleController=Class.create();BubbleController.Constants={};BubbleController.Constants.patternItemIndex="$INDEX$";BubbleController.Constants.patternMarker="/Resource/Map/images/trans.gif?marker";BubbleController.Constants.patternLogo="/Resource/Map/images/trans.gif?logo";BubbleController.Constants.patternTitle="$TITLE$";BubbleController.Constants.patternSubtitles="$SUBTITLES$";BubbleController.Constants.patternLatitude="$LAT$";BubbleController.Constants.patternFormattedWGSLat="$WGSLatFormatted$";BubbleController.Constants.patternFormattedLatitude="$LATFormatted$";BubbleController.Constants.patternFormattedNorthing="$NorthingFormatted$";BubbleController.Constants.patternLongitude="$LON$";BubbleController.Constants.patternFormattedWGSLon="$WGSLonFormatted$";BubbleController.Constants.patternFormattedLongitude="$LONFormatted$";BubbleController.Constants.patternFormattedEasting="$EastingFormatted$";BubbleController.Constants.patternMoreInfoPlaceholder="$MoreInfoPlaceholder$";BubbleController.Constants.patternFavoritesPlaceholder="$FavoritesPlaceholder$";BubbleController.Constants.patternCoordinatesPlaceholder="$CoordinatesPlaceholder$";BubbleController.Constants.patternShortestPathPlaceholder="$ShortestPathPlaceholder$";BubbleController.Constants.patternLogoPlaceholder="$Logo$";BubbleController.Constants.patternFavoriteTitle="$FavoriteTitle$";BubbleController.Constants.patternLookupMapUrl="$MapUrl$";BubbleController.Constants.patternLookupQueryString="$QueryString$";BubbleController.Constants.patternItemJson="$ItemJson$";BubbleController.Constants.patternListingId="$ListingId$";BubbleController.Constants.patternOrgNr="$OrgNr$";BubbleController.Constants.itemSectionShortestPath='Veibeskrivelse <a href="#" id="bDestination" onclick="Menu.setRouteDestination('+BubbleController.Constants.patternItemJson+');">Til hit</a> | <a href="#" onclick="Menu.setRouteStart('+BubbleController.Constants.patternItemJson+');" id="bStart">Herfra</a><br />';BubbleController.Constants.itemSectionLogo='<img id="bLogo" src="'+BubbleController.Constants.patternLogo+'" width="138" height="58" />';BubbleController.Constants.itemSectionMoreInfoListingId='<span id="moreInfoSection"><strong><a href="/Page/Search/Listing.aspx?Vis=info&ListingId='+String(BubbleController.Constants.patternListingId)+'" id="bMoreInfo">Mer info</a></strong><br /></span>';BubbleController.Constants.itemSectionMoreInfoOrgNr='<span id="moreInfoSection"><strong><a href="/Page/Search/Listing.aspx?Vis=jur&OrgNr='+String(BubbleController.Constants.patternOrgNr)+'" id="bMoreInfo">Mer info</a></strong><br /></span>';BubbleController.Constants.itemSectionFavorites='<a href="#" onclick="Utilities.Window.addFavorite('+"'"+BubbleController.Constants.patternFavoriteTitle+"'"+",'"+BubbleController.Constants.patternLookupMapUrl+"?"+BubbleController.Constants.patternLookupQueryString+"'"+')" id="bAddFavorite">Legg til i favoritter</a></p>';BubbleController.Constants.itemSectionCoordinates='<p>'+'<a href="#" id="bShowCoordinates'+BubbleController.Constants.patternItemIndex+'" onclick="bubbleController.showCoordinates('+BubbleController.Constants.patternItemIndex+');">Vis koordinater</a>'+'<div id="bCoordinates'+BubbleController.Constants.patternItemIndex+'" style="display: none">'+'<p>'+'<span>'+'<a class="selected" id="wgs'+BubbleController.Constants.patternItemIndex+'Choice" href="#" onclick="bubbleController.coordinatesDisplay('+"'wgs',"+BubbleController.Constants.patternItemIndex+');">WGS 84</a>'+' | <a id="utm'+BubbleController.Constants.patternItemIndex+'Choice" href="#" onclick="bubbleController.coordinatesDisplay('+"'utm',"+BubbleController.Constants.patternItemIndex+');">UTM33</a>'+' | <a id="desimal'+BubbleController.Constants.patternItemIndex+'Choice" href="#" onclick="bubbleController.coordinatesDisplay('+"'desimal',"+BubbleController.Constants.patternItemIndex+');">Desimal</a>'+'</span>'+'</p>'+'<p id="wgs'+BubbleController.Constants.patternItemIndex+'">'+'Lat: <span id="wgsNorth">'+BubbleController.Constants.patternFormattedWGSLat+'</span><br />'+'Lon: <span id="wgsEast">'+BubbleController.Constants.patternFormattedWGSLon+'</span>'+'</p>'+'<p id="utm'+BubbleController.Constants.patternItemIndex+'" style="display: none;">'+'X: <span id="utmNorth">'+BubbleController.Constants.patternFormattedNorthing+'</span><br />'+'Y: <span id="utmEast">'+BubbleController.Constants.patternFormattedEasting+'</span>'+'</p>'+'<p id="desimal'+BubbleController.Constants.patternItemIndex+'" style="display: none;"> '+'Lat: <span id="wgsNorth">'+BubbleController.Constants.patternFormattedLatitude+'</span><br />'+'Lon: <span id="wgsEast">'+BubbleController.Constants.patternFormattedLongitude+'</span>'+'</p>'+'<p id="gpsExportLinks">'+'<br />'+'<span style="font-weight: bold;">Last ned koordinater til:</span><br />'+'<a id="bCoordsTomTom" target="_blank" href="/Map/WebAtlasMap/Gps/TomTom.aspx?'+BubbleController.Constants.patternLookupQueryString+'">'+'TomTom</a> | <a id="bCoordsGarmin" target="_blank" href="/Map/WebAtlasMap/Gps/GPX.aspx?'+BubbleController.Constants.patternLookupQueryString+'">Garmin</a>'+' | <a id="bCoordsGpx" target="_blank" href="/Map/WebAtlasMap/Gps/GPX.aspx?'+BubbleController.Constants.patternLookupQueryString+'">GPX</a>'+' | <a id="bCoordsLMX" target="_blank" href="/Map/WebAtlasMap/Gps/LMX.aspx?'+BubbleController.Constants.patternLookupQueryString+'">LMX</a></div>'+'</p>'+'</p>';BubbleController.Constants.itemSectionMarkup=''+'<img id="bMarker" src="'+BubbleController.Constants.patternMarker+'" class="poi_img" />'+'<div>'+BubbleController.Constants.patternLogoPlaceholder+'<h2 id="bTitle">'+BubbleController.Constants.patternTitle+'</h2>'+'<p id="bDescription">'+BubbleController.Constants.patternSubtitles+'</p>'+'<p>'+String(BubbleController.Constants.patternMoreInfoPlaceholder)+String(BubbleController.Constants.patternFavoritesPlaceholder)+'<p>'+BubbleController.Constants.patternShortestPathPlaceholder+'Zoom til <a href="#" onclick="mapController.setCenter('+BubbleController.Constants.patternLatitude+', '+BubbleController.Constants.patternLongitude+', 1);" id="bZoomStreet">Gate</a>'+' | <a href="#" onclick="mapController.setCenter('+BubbleController.Constants.patternLatitude+', '+BubbleController.Constants.patternLongitude+', 6);" id="bZoomCity">By</a>'+' | <a href="#" onclick="mapController.setCenter('+BubbleController.Constants.patternLatitude+', '+BubbleController.Constants.patternLongitude+', 13);" id="bZoomCountry">Land</a>'+'</p>'+BubbleController.Constants.patternCoordinatesPlaceholder+'</div>';Object.extend(BubbleController.prototype,{yc:["arrow_left_top","arrow_left_middle","arrow_left_bottom","arrow_right_top","arrow_right_middle","arrow_right_bottom"],xi:[22,22,22,-258,-258,-258],ys:"bubble",mv:null,zx:"bMarker",zF:"bLogo",zp:"bTitle",yX:"bDescription",al:null,yV:null,eT:null,kv:false,jX:null,pY:null,pV:null,qT:new Hash(),pK:"http://www.1881.no/Map/",initialize:function(bD){this.al=bD;this.al.addEventListener("onbeginpan",this.hideBubble.bind(this));this.al.addEventListener("onchangeview",this.hideBubble.bind(this));this.eT=$(this.ys);this.mv=$("bContent");this.pK=Utilities.Window.getBaseUrl();},openItemDialog:function(xW,wX){var xl=$ifDefined(wX,true);this.qT.each((function(oH){var aH=oH.value;var ap=aH["s"+xW];if($defined(ap)){if(xl){this.wE(ap);}this.al.showHotspotDialog(oH.key);}}).bind(this));},wE:function(fq){var aq=this.al.getViewport();if(aq.minLat>fq.Latitude||aq.maxLat<fq.Latitude||aq.minLon>fq.Longitude||aq.maxLon<fq.Longitude){var am=this.al.getMapStyle();if(am!=MapController.Styles.BIRDS_EYE){this.al.setCenter(fq.Latitude,fq.Longitude,5);}else{this.al.setCenter(fq.Latitude,fq.Longitude);}}},displayBubble:function(aS,lw,aC,aD,dj,cY,dN){this.hideBubble();this.mv.update("");var aH=lw.Items;if(!Object.isArray(aH)){aH=[aH];}var i,ao=aH.length;for(i=0;i<ao;i++){var pk=$dom("div");var bh=BubbleController.Constants.itemSectionMarkup+"";var mT="";if($hasValue(aH[i].ListingId)){mT=BubbleController.Constants.itemSectionMoreInfoListingId.sub(BubbleController.Constants.patternListingId,aH[i].ListingId);}else if($hasValue(aH[i].OrgNr)){mT=BubbleController.Constants.itemSectionMoreInfoOrgNr.sub(BubbleController.Constants.patternOrgNr,aH[i].OrgNr);}bh=bh.sub(BubbleController.Constants.patternMoreInfoPlaceholder,mT);var jQ="";if(aH[i].ShowCoordinates){var uf=Utilities.Trans.deg2LLstring(aH[i].Latitude);var us=Utilities.Trans.deg2LLstring(aH[i].Longitude);jQ=BubbleController.Constants.itemSectionCoordinates.sub(BubbleController.Constants.patternFormattedWGSLat,uf);jQ=jQ.sub(BubbleController.Constants.patternFormattedWGSLon,us);}bh=bh.sub(BubbleController.Constants.patternCoordinatesPlaceholder,jQ);var qJ="";if(aH[i].LookupParameters!=null){qJ=BubbleController.Constants.itemSectionShortestPath.gsub(BubbleController.Constants.patternItemJson,Object.toJSON(aH[i].LookupParameters).gsub('"',"'"));}bh=bh.sub(BubbleController.Constants.patternShortestPathPlaceholder,qJ);var ks="";if($hasValue(aH[i].Logo)){ks=BubbleController.Constants.itemSectionLogo.sub(BubbleController.Constants.patternLogo,aH[i].Logo);if(aH[i].LogoUrl!=null){ks="<a href=\""+aH[i].LogoUrl+"\" target=\"_blank\">"+ks+"</a>";}}bh=bh.sub(BubbleController.Constants.patternLogoPlaceholder,ks);var jH="";if($hasValue(aH[i].LookupParameters)){jH=BubbleController.Constants.itemSectionFavorites.sub(BubbleController.Constants.patternLookupMapUrl,this.pK);jH=jH.sub(BubbleController.Constants.patternFavoriteTitle,aH[i].Title);}bh=bh.gsub(BubbleController.Constants.patternFavoritesPlaceholder,jH);bh=bh.sub(BubbleController.Constants.patternMarker,aH[i].Icon.Url);bh=bh.sub(BubbleController.Constants.patternTitle,aH[i].Title);bh=bh.sub(BubbleController.Constants.patternFormattedLatitude,Number(aH[i].Latitude).toFixed(6));bh=bh.sub(BubbleController.Constants.patternFormattedNorthing,Number(aH[i].UtmNorthing).toFixed(1));bh=bh.sub(BubbleController.Constants.patternFormattedLongitude,Number(aH[i].Longitude).toFixed(6));bh=bh.sub(BubbleController.Constants.patternFormattedEasting,Number(aH[i].UtmEasting).toFixed(1));bh=bh.sub(BubbleController.Constants.patternSubtitles,Object.isArray(aH[i].Subtitles)?aH[i].Subtitles.join("<br/>"):"");bh=bh.gsub(BubbleController.Constants.patternItemIndex,String(i));bh=bh.gsub(BubbleController.Constants.patternLatitude,aH[i].Latitude);bh=bh.gsub(BubbleController.Constants.patternLongitude,aH[i].Longitude);bh=bh.gsub(BubbleController.Constants.patternLookupQueryString,Object.toQueryString(aH[i].LookupParameters));pk.innerHTML=bh;this.mv.appendChild(pk);}this.jX=this.wq(dj,cY);this.pY=dj;this.pV=cY;this.positionBubble(lw.Icon.OffsetX,lw.Icon.OffsetY);this.showBubble();},yx:function(){},positionBubble:function(xJ,oP){this.vw(this.yc[this.jX]);var fP=this.xi[this.jX]+xJ;var fT=this.wb(this.jX,oP)+15;this.vt(this.pY,this.pV,fP,fT);},wb:function(ar,oP){if(ar==0||ar==3){return-45;}else{var aJ=this.eT.getHeight();if(ar==2||ar==5){return-aJ+30;}else{return(-aJ/2);}}},vt:function(dj,cY,fP,fT){this.eT.setStyle({"left":(dj+fP)+"px","top":(cY+fT)+"px"});},hideBubble:function(){if(this.kv){this.eT.hide();this.kv=false;}},showBubble:function(){if(!this.kv){this.eT.show();this.kv=true;}},vw:function(jl){var jS=this.eT.classNames().toArray();var i,ao=jS.length;var pm=false;for(i=0;i<ao;i++){if(jS[i]==jl){pm=true;break;}else if(jS[i]!="bubble"){this.eT.removeClassName(jS[i]);break;}}if(!pm){this.eT.addClassName(jl);}},zP:function(jl){if(jl!="bubble"){this.eT.removeClassName(jl);}},wq:function(dj,cY){var op=this.al.getDimensions();var bq=op.width/2>dj?0:3;var sd=op.height/3;if(cY<sd)return 0+bq;if(cY<sd*2)return 1+bq;else return 2+bq;},loadBubbleClusters:function(aH,bN){var bj=$ifDefined(bN.collectionId,"_defaultCollection");if(Object.isArray(aH)){aH=aH.clone().reverse();var dv=$ifDefined(bN.zoom,false);var mz=$ifDefined(bN.zoomLowerBound,1);var cb=this.vM(aH,bj,dv,mz);this.al.setHotspots(bj,cb,$ifDefined(bN.upperBound,100));}else{this.al.removeHotspots(bj);}},vM:function(aL,bj,dv,mz){var bu=Number.MAX_VALUE,bs=Number.MAX_VALUE,bo=Number.MIN_VALUE,bp=Number.MIN_VALUE;var cb=[];var i,ao=aL.length;var lv={};for(i=0;i<ao;i++){if(dv){if(aL[i].Latitude>bp){bp=aL[i].Latitude;}if(aL[i].Latitude<bs){bs=aL[i].Latitude;}if(aL[i].Longitude<bu){bu=aL[i].Longitude;}if(aL[i].Longitude>bo){bo=aL[i].Longitude;}}cb.push([aL[i].Id,aL[i].Icon.Url,aL[i].Latitude,aL[i].Longitude,null,aL[i],this.displayBubble.bind(this),0,15,aL[i].Icon.OffsetX,aL[i].Icon.OffsetY]);if(aL[i].Items!=null){lv={};aL[i].Items.each(function(ap){lv["s"+ap.Id]=ap;});this.qT.set(aL[i].Id,lv);}}if(ao>0&&dv){this.al.setViewport(bu,bs,bo,bp,mz);}return cb;},zC:function(bi,ap){},yv:function(bi,ap){},yN:function(bi,ap){this.al.setCenter(ap.Location.Northing,ap.Location.Easting,2);},yO:function(bi,ap){this.al.setCenter(ap.Location.Northing,ap.Location.Easting,6);},yM:function(bi,ap){this.al.setCenter(ap.Location.Northing,ap.Location.Easting,13);},moreInfo:function(xs){window.location.href="/Page/Search/Listing.aspx?Vis=info&ListingId="+xs;},showCoordinates:function(ar){$("bShowCoordinates"+ar).hide();this.coordinatesDisplay("wgs",ar);$("bCoordinates"+ar).show();this.positionBubble();},coordinatesDisplay:function(aP,ar){var tx=aP+ +ar;[$('wgs'+ar),$('utm'+ar),$('desimal'+ar)].each(function(e){if(e.id!=tx){$(e.id+"Choice").removeClassName("selected");e.hide();}else{$(e.id+"Choice").addClassName("selected");e.show();}});}});