var evolveGMaps={};(function(n){function c(){var i=$(".section-header").css("backgroundColor"),n=new google.maps.LatLngBounds;$(".location-item").each(function(){if($(this).data("latlng")!==""&&$(this).data("latlng").split(",").length===2){var r=$(this).data("latlng").split(","),f=new google.maps.LatLng(r[0],r[1]),e=new google.maps.Marker({position:f,icon:l($(this).attr("data-color")&&$(this).data("color")!==""?"#"+$(this).data("color"):i),map:t,brandId:parseInt($(this).data("brand"))});google.maps.event.addListener(e,"click",a);u.push(e);n.extend(f)}});s&&t.fitBounds(n)}function l(n){return{path:"M160,0C71.641,0,0,71.625,0,160c0,24.75,5.625,48.219,15.672,69.125 C16.233, 230.313,160,512,160,512l142.594-279.375C313.719, 210.844,320,186.156,320,160C320, 71.625,248.375,0,160,0",anchor:new google.maps.Point(160,512),fillColor:n,fillOpacity:1,scale:.09}}function a(){var n=this.getPosition(),t=n.lat()+","+n.lng();$(".location-item").each(function(){if($(this).data("latlng")===t){$(this).click();return}})}function v(){var n=t.getCenter();if(n.lat!==i||n.lng!==r){if(i=n.lat,r=n.lng,o){o=!1;return}y()}}function y(){var n=t.getCenter();$(".location-item").each(function(){if($(this).data("latlng")!==""){var t=$(this).data("latlng").split(",");$(this).data("geodistance",google.maps.geometry.spherical.computeDistanceBetween(n,new google.maps.LatLng(t[0],t[1])))}else $(this).data("geodistance",25e6)});$(".location-item").sort(function(n,t){return $(n).data("geodistance")>$(t).data("geodistance")?1:$(n).data("geodistance")<$(t).data("geodistance")?-1:0}).appendTo(".location-listings-list")}var t=null,i=-41.262484,r=173.19179,f=6,e=null,u=[],o=!1,s=!0,h=$("#location-map").data("enablegeolocation");n.init=function(){t=new google.maps.Map($("#location-map")[0],{center:new google.maps.LatLng(i,r),zoom:f});google.maps.event.addListener(t,"idle",v);c();e=new google.maps.places.Autocomplete($(".location-autocomplete")[0],{types:["geocode"],componentRestrictions:{country:["nz"]}});e.addListener("place_changed",n.autocompletePicked);h&&navigator.geolocation&&navigator.geolocation.getCurrentPosition(n.geoLocated)};n.setCentre=function(n,u){i=n;r=u;t===null||t.setCenter(new google.maps.LatLng(i,r))};n.setZoom=function(n){f=n;t===null||t.setZoom(f)};n.geoLocated=function(t){n.setCentre(t.coords.latitude,t.coords.longitude);n.setZoom(10)};n.autocompletePicked=function(){var t=e.getPlace();n.setCentre(t.geometry.location.lat(),t.geometry.location.lng());n.setZoom(10)};n.openListing=function(n){var e;if(n.data("latlng")!==""&&n.data("latlng").split(",").length===2){var i=n.data("latlng").split(","),r=$(".location-item"),f=0;r.each(function(){if(f++,$(this).data("latlng")==i){var n=r[f-1];n.parentNode.scrollTop=n.offsetTop;return}});e=new google.maps.LatLng(i[0],i[1]);$.each(u,function(){if(this.setAnimation(null),e.equals(this.getPosition())){o=!0;t.panTo(this.getPosition());this.setAnimation(google.maps.Animation.BOUNCE);return}})}};n.closeListing=function(){$.each(u,function(){this.setAnimation(null)})};n.showAllMarkers=function(){$.each(u,function(){this.map||this.setMap(t)})};n.filterMarkers=function(n){$.each(u,function(){$.inArray(this.brandId,n)>-1?this.map||this.setMap(t):this.map&&this.setMap(null)})}})(evolveGMaps),function(n,t){t(function(){t(".location-listings").on("click",".location-item",function(n){var i=t(n.target),r;if(i.is("a")&&i.attr("href")!=="#")return!0;r=t(this).find(".location-item-details").clone();n.preventDefault();t(".location-item").not(this).removeClass("active");t(this).addClass("active");t(".location-item-popout").addClass("active");t(".location-item-details-placeholder").html(r);evolveGMaps.openListing(t(this))});t(".location-listings").on("click",".location-close",function(n){n.preventDefault();evolveGMaps.closeListing();t(".location-item").removeClass("active");t(".location-item-popout").removeClass("active")});t(".brand-filter-list").length&&t(".brand-filter-list input[type='checkbox']").change(function(){if(t(this).val()==="all")t(".brand-filter-list input[type='checkbox']").not(t(this)).prop("checked",!1),t(this).prop("checked",!0),t(".location-item").show(),evolveGMaps.showAllMarkers();else{t(".brand-filter-list input[type='checkbox'][value='all']").prop("checked",!1);var n=[];t(".location-item").hide();t(".brand-filter-list input[type='checkbox']:checked").each(function(){t(".location-item[data-brand='"+t(this).val()+"']").show();n.push(parseInt(t(this).val()))});evolveGMaps.filterMarkers(n)}})})}(window,jQuery)