var nachtcaches={defaultMapLocation:[51.151786,10.415039],defaultMapZoom:7,caches:[],markers:{},overlays:{},geocoder:new google.maps.Geocoder,codeRegex:/^GC[A-Z0-9]+$/,overlayVisible:!1,cacheTypes:["traditional","multi","mystery","wherigo","letterbox"],markerIcons:{},updateInProgress:!1,currentBounds:null,assets:{cacheTypeIcons:{traditional:"/assets/traditional-37c4cb26de2efd93ea913137b019a7fc.png",multi:"/assets/multi-78f49c7093943d3bcf45e2d0cd2c25a8.png",mystery:"/assets/mystery-cc6dc278c22f9c18432ea20cde301fc7.png",letterbox:"/assets/letterbox-9527f09c3a93f3ea0a117f7e8c4253c9.png",wherigo:"/assets/wherigo-f2a037544f5e106851401cf13d04237d.png"},stars:{10:"/assets/stars/10-71143ce3ee14ee5285f2e40da539f086.png",15:"/assets/stars/15-b7bee203bb87d23343895a3fe0210ab1.png",20:"/assets/stars/20-94215fa80db38e95d94111e3a61afba6.png",25:"/assets/stars/25-5ec4e1e94795da450d6efe6ad8a2ebdb.png",30:"/assets/stars/30-50abb3c48e7a7fcd08d9c1eacebf75e0.png",35:"/assets/stars/35-f3c9ec3d0ba36a66d54ba3e8e36874eb.png",40:"/assets/stars/40-402ff111e419bd5ba87f9647149b20b1.png",45:"/assets/stars/45-d1d5de7a8849fd25ad26f268e7e8159e.png",50:"/assets/stars/50-c2bd4ce0edf4976ce0b972bc097d76a5.png"}}};nachtcaches.buildBoundsQueryString=function(){var a=nachtcaches.map.getBounds();return[a.getSouthWest().lat(),a.getSouthWest().lng(),a.getNorthEast().lat(),a.getNorthEast().lng()].join(",")},nachtcaches.updateHash=function(){var a=nachtcaches.map.getCenter(),b=nachtcaches.map.getZoom();window.location.hash=[a.lat(),a.lng(),b].join(",")},nachtcaches.updateCaches=function(){var a=nachtcaches.buildBoundsQueryString();$.getJSON("/caches.json",{bounds:a},function(a){nachtcaches.caches=a,nachtcaches.didReceiveCaches()})},nachtcaches.didReceiveCaches=function(){var a=[];for(var b=0;b<nachtcaches.caches.length;b++){var c=nachtcaches.caches[b];a.push(c.code),c.code in nachtcaches.markers||nachtcaches.addMarkerForCache(c);if(!(c.code in nachtcaches.overlays)){var d=nachtcaches.markers[c.code].getPosition();nachtcaches.addOverlayForCache(c,d)}}for(var e in nachtcaches.markers)if(a.length==0||a.indexOf(e)==-1)nachtcaches.markers[e].setMap(null),delete nachtcaches.markers[e];for(var e in nachtcaches.overlays)if(a.length==0||a.indexOf(e)==-1)nachtcaches.overlays[e].setMap(null),delete nachtcaches.overlays[e]},nachtcaches.updateExportLinks=function(){var a=nachtcaches.buildBoundsQueryString();$("#kmlLink").attr("href","/caches.kml?bounds="+a),$("#rssLink").attr("href","/caches.atom?bounds="+a),$("#gpxLink").attr("href","/caches.gpx?bounds="+a)},nachtcaches.performSearch=function(a){if($.trim(a).length==0)return!1;nachtcaches.geocoder.geocode({address:a,language:"de",region:"de"},function(a,b){b==google.maps.GeocoderStatus.OK&&a.length>0?(nachtcaches.map.setCenter(a[0].geometry.location),nachtcaches.map.setZoom(11),nachtcaches.updateCaches()):nachtcaches.showError("Ort nicht gefunden.")})},nachtcaches.addMarkerForCache=function(a){var b=new google.maps.Marker({position:new google.maps.LatLng(a.latitude,a.longitude),map:nachtcaches.map,title:a.name,icon:nachtcaches.markerIcons[a.type]});google.maps.event.addListener(b,"mouseover",function(){nachtcaches.overlayHideTimeout&&(clearTimeout(nachtcaches.overlayHideTimeout),nachtcaches.overlayHideTimeout=null),nachtcaches.hideAllOverlays(),nachtcaches.overlays[a.code].show()}),google.maps.event.addListener(b,"mouseout",function(){nachtcaches.overlayHideTimeout=setTimeout(function(){nachtcaches.hideAllOverlays()},1e3)}),nachtcaches.markers[a.code]=b},nachtcaches.addOverlayForCache=function(a,b){var c=new nachtcaches.Overlay(nachtcaches.map,a,b);nachtcaches.overlays[a.code]=c},nachtcaches.removeMarkers=function(){for(var a in nachtcaches.markers)nachtcaches.markers[a].setMap(null),delete nachtcaches.markers[a]},nachtcaches.removeOverlays=function(){for(var a in nachtcaches.overlays)nachtcaches.overlays[a].setMap(null),delete nachtcaches.overlays[a]},nachtcaches.hideAllOverlays=function(){for(var a in nachtcaches.overlays)nachtcaches.overlays[a].hide()},nachtcaches.boundsDidChange=function(){nachtcaches.updateHash(),nachtcaches.updateExportLinks(),nachtcaches.map.getZoom()>=9?($("#exportControls").css("visibility","visible"),nachtcaches.updateCaches()):(nachtcaches.removeOverlays(),nachtcaches.removeMarkers(),$("#exportControls").css("visibility","hidden"))},nachtcaches.showLoadingOverlay=function(){var a=$('<div id="loadingOverlay" class="mapOverlay">&nbsp;</div>');$(document.body).append(a),nachtcaches.overlayVisible=!0},nachtcaches.hideLoadingOverlay=function(){$("#loadingOverlay").remove(),nachtcaches.overlayVisible=!1},nachtcaches.setupMap=function(a){nachtcaches.map=new google.maps.Map($("#map")[0],{zoom:a.zoom,center:a.location,mapTypeId:google.maps.MapTypeId.TERRAIN,disableDefaultUI:!0}),google.maps.event.addListener(nachtcaches.map,"click",function(){nachtcaches.hideAllOverlays()});for(var b=0;b<nachtcaches.cacheTypes.length;b++){var c=nachtcaches.cacheTypes[b];nachtcaches.markerIcons[c]=new google.maps.MarkerImage(nachtcaches.assets.cacheTypeIcons[c],new google.maps.Size(20,20),new google.maps.Point(0,0),new google.maps.Point(10,10))}},nachtcaches.getLocation=function(){var a=null;return a=nachtcaches.getLocationFromHash(),a||(a=nachtcaches.getLocationFromGoogle()),a||(a=nachtcaches.getDefaultLocation()),a},nachtcaches.getLocationFromHash=function(){if(window.location.hash.length<1)return!1;var a=window.location.hash.substring(1).split(",");if(a.length!==3)return!1;var b=parseFloat(a[0]),c=parseFloat(a[1]),d=parseInt(a[2]);return!b||!c||!d?!1:{location:new google.maps.LatLng(b,c),zoom:d}},nachtcaches.setLocationFromGeolocation=function(){nachtcaches.showLoadingOverlay();if(navigator.geolocation)navigator.geolocation.getCurrentPosition(function(a){var b=new google.maps.LatLng(a.coords.latitude,a.coords.longitude);nachtcaches.hideLoadingOverlay(),nachtcaches.map.setCenter(b),nachtcaches.map.setZoom(11)},function(a){var b=nachtcaches.getLocationFromGoogle();nachtcaches.hideLoadingOverlay(),b.location?(nachtcaches.map.setCenter(b.location),nachtcaches.map.setZoom(b.zoom)):nachtcaches.showError("Position konnte nicht bestimmt werden.")});else{var a=nachtcaches.getLocationFromGoogle();nachtcaches.hideLoadingOverlay(),a.location?(nachtcaches.map.setCenter(a.location),nachtcaches.map.setZoom(a.zoom)):nachtcaches.showError("Position konnte nicht bestimmt werden.")}},nachtcaches.getLocationFromGoogle=function(){if(!google.loader.ClientLocation)return!1;var a=google.loader.ClientLocation.latitude,b=google.loader.ClientLocation.longitude;return{location:new google.maps.LatLng(a,b),zoom:11}},nachtcaches.getDefaultLocation=function(){var a=nachtcaches.defaultMapLocation[0],b=nachtcaches.defaultMapLocation[1];return{location:new google.maps.LatLng(a,b),zoom:nachtcaches.defaultMapZoom}},nachtcaches.setSelectedMapTypeButton=function(a){$("#mapTypeControls button").each(function(){$(this).attr("id")==a?$(this).addClass("selected"):$(this).removeClass("selected")})},nachtcaches.showReportCacheDialog=function(a){$.ajax({url:"/report.html",success:function(b){var c=$(b);c.find("#reportCacheDialog").attr("data-code",a),c.find("h2 > span").text(a),$("#addCacheOverlay").remove(),$(document.body).append(c),$("#closeReportCacheDialog").click(nachtcaches.closeReportCacheDialog),$("#reportCacheDialog button").click(nachtcaches.userDidClickReportCacheButton)}})},nachtcaches.closeReportCacheDialog=function(){$("#reportCacheOverlay").fadeOut("fast",function(){$("#reportCacheOverlay").remove()})},nachtcaches.userDidClickReportCacheButton=function(){var a=$("#reportCacheDialog").attr("data-code"),b=$("#reportCacheDialog textarea").val();$.ajax({url:"/caches/"+a+"/report",type:"POST",data:{comment:b},complete:nachtcaches.reportCacheRequestDidComplete})},nachtcaches.reportCacheRequestDidComplete=function(a,b){$("#reportCacheOverlay").remove(),a.status==200?nachtcaches.showNotice("Der Cache wurde erfolgreich gemeldet."):nachtcaches.showError("Es ist ein Fehler beim Melden des Caches aufgetreten.")},nachtcaches.showAddCacheDialog=function(){$.ajax({url:"/add.html",success:function(a){$("#reportCacheOverlay").remove(),$(document.body).append($(a)),$("#closeAddCacheDialog").click(nachtcaches.closeAddCacheDialog),$("#addCacheDialog button").click(nachtcaches.userDidClickAddCacheButton),$("#addCacheDialog input").keydown(function(a){a.keyCode==13&&nachtcaches.userDidClickAddCacheButton()})}})},nachtcaches.closeAddCacheDialog=function(){$("#addCacheDialog").fadeOut("fast",function(){$("#addCacheOverlay").remove()})},nachtcaches.userDidClickAddCacheButton=function(){var a=$("#addCacheDialog input").val().toUpperCase();$("#addCacheDialog div.notice").text(""),$("#addCacheDialog div.error").text("");if(!a||!nachtcaches.codeRegex.test(a)){$("#addCacheDialog div.error").text("Bitte gebe einen gültigen GC-Code ein.");return}$.ajax({url:"/caches",type:"POST",data:{code:a},complete:nachtcaches.addCacheRequestDidComplete})},nachtcaches.addCacheRequestDidComplete=function(a,b){var c={};try{c=$.parseJSON(a.responseText)}catch(d){}a.status==200?($("#addCacheOverlay").remove(),nachtcaches.showNotice("Danke! Der Cache wurde erfolgreich eingetragen.")):$("#addCacheDialog div.error").text(c.error||"Es ist ein Fehler beim Eintragen des Caches aufgetreten.")},nachtcaches.showNotice=function(a){var b=$('<div id="noticeBar"></div>').text(a);nachtcaches.noticeBarHideTimeout&&(clearTimeout(nachtcaches.noticeBarHideTimeout),nachtcaches.noticeBarHideTimeout=null),$("#noticeBar").remove(),$(document.body).append(b),nachtcaches.noticeBarHideTimeout=setTimeout(function(){$("#noticeBar").fadeOut(function(){$("#noticeBar").remove()})},2e3)},nachtcaches.showError=function(a){var b=$('<div id="errorBar"></div>').text(a);nachtcaches.errorBarHideTimeout&&(clearTimeout(nachtcaches.errorBarHideTimeout),nachtcaches.errorBarHideTimeout=null),$("#errorBar").remove(),$(document.body).append(b),nachtcaches.errorBarHideTimeout=setTimeout(function(){$("#errorBar").fadeOut(function(){$("#errorBar").remove()})},2e3)},nachtcaches.setupEventListeners=function(){var a=function(){var a=$("#search input")[0].value;nachtcaches.performSearch(a)};setInterval(nachtcaches.checkBounds,500),$(document.body).keydown(function(a){a.keyCode==27&&($("#addCacheDialog").length>0&&nachtcaches.closeAddCacheDialog(),$("#reportCacheDialog").length>0&&nachtcaches.closeReportCacheDialog())}),$("#search button").click(a),$("#search input").keydown(function(b){b.keyCode==13&&a()}),$("#zoomOutButton").click(function(){var a=nachtcaches.map.getZoom();nachtcaches.map.setZoom(a-1)}),$("#zoomInButton").click(function(){var a=nachtcaches.map.getZoom();nachtcaches.map.setZoom(a+1)}),$("#roadmapMapTypeButton").click(function(){nachtcaches.map.setMapTypeId(google.maps.MapTypeId.ROADMAP),nachtcaches.setSelectedMapTypeButton("roadmapMapTypeButton")}),$("#satelliteMapTypeButton").click(function(){nachtcaches.map.setMapTypeId(google.maps.MapTypeId.SATELLITE),nachtcaches.setSelectedMapTypeButton("satelliteMapTypeButton")}),$("#hybridMapTypeButton").click(function(){nachtcaches.map.setMapTypeId(google.maps.MapTypeId.HYBRID),nachtcaches.setSelectedMapTypeButton("hybridMapTypeButton")}),$("#terrainMapTypeButton").click(function(){nachtcaches.map.setMapTypeId(google.maps.MapTypeId.TERRAIN),nachtcaches.setSelectedMapTypeButton("terrainMapTypeButton")}),$("#geolocationButton").click(function(){nachtcaches.overlayVisible||nachtcaches.setLocationFromGeolocation()}),$("#addCacheLink").click(function(a){nachtcaches.overlayVisible||(nachtcaches.showAddCacheDialog(),a.preventDefault())})},nachtcaches.checkBounds=function(){var a=nachtcaches.map.getBounds();a!==undefined&&!a.equals(nachtcaches.currentBounds)&&(nachtcaches.boundsDidChange(),nachtcaches.currentBounds=a)},nachtcaches.init=function(){nachtcaches.setupEventListeners(),nachtcaches.setupMap(nachtcaches.getLocation())},$(document).ready(nachtcaches.init),nachtcaches.Overlay=function(a,b,c){this.cache=b,this.markerPosition=c,this.div=$('<div class="cacheoverlay">                   <div class="inner">                     <h3></h3>                     <div>                       <div class="box difficulty">                         <img width="60" height="12">                         Difficulty                       </div>                       <div class="box terrain">                         <img width="60" height="12">                         Terrain                       </div>                       <div class="box gcvote">                         <img width="60" height="12">                         GCVote                       </div>                     </div>                     <ol class="segmentedControl">                       <li><a class="gc">Auf geocaching.com anzeigen</a>                       <li><a href="#" class="report">Cache melden</a>                     </ol>                   </div>                 </div>'),this.div.hover(function(){nachtcaches.overlayHideTimeout&&(clearTimeout(nachtcaches.overlayHideTimeout),nachtcaches.overlayHideTimeout=null)},function(){nachtcaches.overlayHideTimeout=setTimeout(function(){nachtcaches.hideAllOverlays()},1e3)}),this.div.find("h3").text(this.cache.name),this.div.find("a.gc").attr("href","http://coord.info/"+this.cache.code);if(this.cache.gcvote_rating_median!=0&&this.cache.gcvote_votes>=10){var d=Math.round(this.cache.gcvote_rating_median*2)/2,e=this.cache.gcvote_rating_median+" bei "+this.cache.gcvote_votes+" Bewertungen";this.div.find(".gcvote img").attr("src",nachtcaches.assets.stars[d*10]).attr("title",e)}else this.div.find(".gcvote").remove();this.cache.difficulty?this.div.find(".difficulty img").attr("src",nachtcaches.assets.stars[this.cache.difficulty*10]):this.div.find(".difficulty").remove(),this.cache.terrain?this.div.find(".terrain img").attr("src",nachtcaches.assets.stars[this.cache.terrain*10]):this.div.find(".terrain").remove(),this.div.find("a.report").click(function(){return nachtcaches.showReportCacheDialog(b.code),!1});var f=["mousedown","dblclick","DOMMouseScroll","contextmenu"],g=this;for(var h=0;h<f.length;h++)google.maps.event.addDomListener(g.div[0],f[h],g._onClick);this.setMap(a)},nachtcaches.Overlay.prototype=new google.maps.OverlayView,nachtcaches.Overlay.prototype.onAdd=function(){this.div.appendTo(this.getPanes().floatPane)},nachtcaches.Overlay.prototype.onRemove=function(){this.div.remove()},nachtcaches.Overlay.prototype.draw=function(){var a=this.getProjection(),b=a.fromLatLngToDivPixel(this.markerPosition),c=b.x-27,d=b.y-this.div.height()-19;this.div.css({top:d+"px",left:c+"px"})},nachtcaches.Overlay.prototype.show=function(){this.div.css("visibility","visible")},nachtcaches.Overlay.prototype.hide=function(){this.div.css("visibility","hidden")},nachtcaches.Overlay.prototype._onClick=function(a){navigator.userAgent.toLowerCase().indexOf("msie")!=-1&&document.all?window.event.cancelBubble=!0:a.stopPropagation()}
