function fitPlacesToBounds(){var a=_.map($(".place"),function(a){return $(a).data("marker").position});if(_.size(a)!==0){var b=new google.maps.LatLngBounds(_.first(a));_.each(a,function(a){b.extend(a)}),googleMap.fitBounds(b)}}function setupMarkersForPlaces(){$(".place").each(function(){if(_.isUndefined($(this).data("marker"))){var a=$(this).find("label a");$(this).data("marker",new google.maps.Marker({position:new google.maps.LatLng(this.dataset.lat,this.dataset.lng),map:googleMap,title:a.text()+(this.dataset.hasEvents=="true"?" [ has Events ]":"")+(this.dataset.hasSpecials=="true"?" [ has Specials ]":""),icon:new google.maps.MarkerImage(this.dataset.iconUrl,new google.maps.Size(32,32),null,null,new google.maps.Size(32,32))}));var b=$(this).data("marker");google.maps.event.addListener(b,"click",function(){window.location=a.attr("href")})}})}function renderGoogleMap(){$(".google-map").first().each(function(a,b){var c={mapTypeId:google.maps.MapTypeId.ROADMAP,streetViewControl:!1,mapTypeControl:!1,scaleControl:!1,maxZoom:18,minZoom:10};typeof b.dataset.lat!="undefined"&&typeof b.dataset.lng!="undefined"?_.extend(c,{center:new google.maps.LatLng(b.dataset.lat*1,b.dataset.lng*1)}):_.extend(c,{center:getLocationMunich()}),typeof b.dataset.zoom!="undefined"?_.extend(c,{zoom:b.dataset.zoom*1}):_.extend(c,{zoom:14}),googleMap=new google.maps.Map(b,c),typeof b.dataset.marker!="undefined"&&b.dataset.marker=="true"&&new google.maps.Marker({position:c.center,map:googleMap}),google.maps.event.addListener(googleMap,"idle",function(){getPlacesAround(googleMap.getCenter(),10)})})}function distanceBetweenPoints(a,b){var c=6378.137,d=a.lat()/180,e=a.lng()/180,f=b.lat()/180,g=b.lng()/180,h=f-d,i=g-e,j=Math.sin(h/2)*Math.sin(h/2)+Math.cos(d)*Math.cos(f)*Math.sin(i/2)*Math.sin(i/2),k=2*Math.atan2(Math.sqrt(j),Math.sqrt(1-j)),l=c*k;return l}function handleGeolocation(){if(typeof currentLocation!="undefined"&&currentLocation["default"]!=1)return initialLocation=new google.maps.LatLng(currentLocation.lat,currentLocation.lng),googleMap.setCenter(initialLocation),new google.maps.Marker({position:initialLocation,map:googleMap,title:"Now Here",animation:google.maps.Animation.DROP,visible:!0}),!0;if(navigator.geolocation){var a=!0;navigator.geolocation.getCurrentPosition(function(a){initialLocation=new google.maps.LatLng(a.coords.latitude,a.coords.longitude),positionDetected(initialLocation)},function(){handleNoGeolocation(a)})}else a=!1,handleNoGeolocation(a)}function getPlacesAround(a,b){if(_.isUndefined($("#places").data("lastUpdated")))$("#places").data("lastUpdated",new Date);else{if((new Date-$("#places").data("lastUpdated"))/3600<.5)return!1;$("#places").data("lastUpdated",new Date)}jQuery.get($("#places").get(0).dataset.source,{lat:a.lat(),lng:a.lng(),radius:b},function(a){if(a===""||a===" ")return!1;var b=$(a).filter(".place");b.each(function(a,b){$("#places .place[data-place-id="+b.dataset.placeId+"]").length==0&&$("#places").append(b)}),setupMarkersForPlaces()},"html")}function positionDetected(a){googleMap.setCenter(a),new google.maps.Marker({position:a,map:googleMap,title:"Now Here",animation:google.maps.Animation.DROP,visible:!0}),$.post("/nh/location",{_method:"put",lat:a.lat(),lng:a.lng()})}function handleNoGeolocation(a){a==1?console.log("Geolocation service failed"):console.log("Your browser doesn't support geolocation"),initialLocation=getLocationMunich(),googleMap.setCenter(initialLocation),$.post("/nh/location",{_method:"put",lat:initialLocation.lat(),lng:initialLocation.lng()})}function getLocationMunich(){return new google.maps.LatLng(48.152373,11.620542)}$(document).ready(function(){typeof google!="undefined"&&google.maps.event.addDomListener(window,"load",function(){renderGoogleMap(),handleGeolocation()}),$(".map-resizer .open").live("click",function(){return $(".google-map").height(500),$(this).removeClass("open"),$(this).addClass("close"),google.maps.event.trigger(googleMap,"resize"),!1}),$(".map-resizer .close").live("click",function(){return $(".google-map").height(250),$(this).removeClass("close"),$(this).addClass("open"),google.maps.event.trigger(googleMap,"resize"),!1})})
