function directToAdvancedSearch(n){n.preventDefault();var t=document.getElementById("MainSearchForm");t.action="/Browse/AdvancedSearch.aspx";t.submit()}function setupMap(){function t(n,t,i){return(i.y-n.y)*(t.x-n.x)>=(t.y-n.y)*(i.x-n.x)}function r(n,i,r,u){return t(n,r,u)!==t(i,r,u)&&t(n,i,r)!==t(n,i,u)}function u(n,t){for(var o=t.length,u={x:0,y:n.y},s=0,f,e,i=0;i<o;i=i+1)f=t[i],e=t[(i+1)%o],u.x=Math.min(u.x,Math.min(f.x,e.x)-1),s+=r(u,n,f,e)?1:0;return s%2>0}function i(t,i){var r=t.attr("src").indexOf("_",0)>0?t.attr("src").indexOf("_",0):t.attr("src").indexOf(".",0),u=t.attr("src");r>-1?u.indexOf("_click")===-1?t.attr("src",u.substring(0,r)+(i?"_click":"")+".png"):n():n()}function n(){$("img.mapHoverState").hide();$("a.region").removeClass("hovered")}$(".js-HomePageMap-newZealandTab a").on("click",function(n){n.preventDefault();$(".js-HomePageMap-newZealandMap").show();$(".js-HomePageMap-australiaMap").hide();$(".js-HomePageMap-pacificIslandsMap").hide();$(".js-HomePageMap-australiaTab a").removeAttr("class");$(".js-HomePageMap-newZealandTab a").attr("class","is-active");$(".js-HomePageMap-pacificIslandsTab a").removeAttr("class")});$(".js-HomePageMap-australiaTab a").on("click",function(n){n.preventDefault();$(".js-HomePageMap-newZealandMap").hide();$(".js-HomePageMap-australiaMap").show();$(".js-HomePageMap-pacificIslandsMap").hide();$(".js-HomePageMap-newZealandTab a").removeAttr("class");$(".js-HomePageMap-australiaTab a").attr("class","is-active");$(".js-HomePageMap-pacificIslandsTab a").removeAttr("class")});$(".js-HomePageMap-pacificIslandsTab a").on("click",function(n){n.preventDefault();$(".js-HomePageMap-newZealandMap").hide();$(".js-HomePageMap-australiaMap").hide();$(".js-HomePageMap-pacificIslandsMap").removeClass("visuallyHidden").show();$(".js-HomePageMap-newZealandTab a").removeAttr("class");$(".js-HomePageMap-australiaTab a").removeAttr("class");$(".js-HomePageMap-pacificIslandsTab a").attr("class","is-active")});$(window).resize(resizePacificIslandsMap);$("img.mapHoverState").on("click touchend",function(n){window.location.href=$("area#ctl00_PH_Content_"+n.target.id.substring(0,n.target.id.indexOf("Hover"))+"MapArea").attr("href")});$(".js-HomePageMap a").mouseenter(function(t){t.preventDefault();n();$(".js-HomePageMap img#"+t.target.id.substring(17,t.target.id.length)+"Hover").show()});$(".js-HomePageMap a").mouseleave(function(t){t.preventDefault();n()});$(".js-HomePageMap a").mouseup(function(t){t.preventDefault();n()});$(".js-HomePageMap a.region").mousedown(function(n){n.preventDefault();i($(".js-HomePageMap img#"+n.target.id.substring(17,n.target.id.length)+"Hover"),!0)});$("area").mouseenter(function(t){n();$(".js-HomePageMap a#"+t.target.id.substring(0,t.target.id.indexOf("MapArea",0))).addClass("hovered");$(".js-HomePageMap img#"+t.target.id.substring(17,t.target.id.indexOf("MapArea",0))+"Hover").show()});$("img.mapHoverState").mousemove(function(t){n();for(var o=t.pageX-$("#"+t.target.id).parent().offset().left,s=t.pageY-$("#"+t.target.id).parent().offset().top,r=$("area#ctl00_PH_Content_"+t.target.id.substring(0,t.target.id.indexOf("Hover"))+"MapArea").attr("coords").split(","),e=[],i=0,f=0;i<r.length;)e[f]={x:r[i],y:r[i+1]},i=i+2,f=f+1;u({x:o,y:s},e)&&($(".js-HomePageMap a#ctl00_PH_Content_"+t.target.id.substring(0,t.target.id.indexOf("Hover",0))).addClass("hovered"),$("#"+t.target.id).show())});$("img.mapHoverState").mouseleave(function(t){n();i($("#"+t.target.id,!1))});$("img.mapHoverState").mousedown(function(n){i($("#"+n.target.id),!0)});$("img.mapHoverState").mouseup(function(){n()})}function resizePacificIslandsMap(){$(".js-HomePageMap-pacificIslandsMap").css("height",$(".js-MapView").height()-95)}function HomePageMap(n,t,i,r){function u(){return $(this.image).width()/this.initialMapWidth}function f(){return $(this.image).height()/this.initialMapHeight}this.map=n;this.image=t;this.initialMapWidth=i;this.initialMapHeight=r;this.regionX=[];this.regionY=[];this.regionWidth=[];this.regionHeight=[];this.labelX=[];this.labelY=[];this.scaleX=u;this.scaleY=f}function storeMapRegions(n){$(n.map).find(".mapHoverState").each(function(t){var u=$(this).css("left"),f=$(this).css("top"),i,r;n.regionX[t]=u.slice(0,-2);n.regionY[t]=f.slice(0,-2);i=$(this).css("width");r=$(this).css("height");n.regionWidth[t]=i.slice(0,-2);n.regionHeight[t]=r.slice(0,-2)})}function storeMapLabels(n){$(n.map).find(".js-mapLabel").each(function(t){var i,r;i=$(this).hasClass("is-rightAligned")?$(this).css("right"):$(this).css("left");r=$(this).css("top");n.labelX[t]=i.slice(0,-2);n.labelY[t]=r.slice(0,-2)})}function resizeMapItems(n,t,i,r,u,f,e,o){$(n).find(t).each(function(n){var t=i[n]*e,s=r[n]*o,h;if(u&&f)var c=u[n]*e,l=f[n]*o,h=!0;else h=!1;$(this).hasClass("is-rightAligned")?$(this).css({top:s,right:t}):$(this).css({top:s,left:t});h&&$(this).css({width:c,height:l})})}function centerMap(n){var i=$(".js-HomePageMap").width(),t=$(".js-HomePageMap").height()-135,r;mapWidth=$(n.image).width();mapHeight=$(n.image).height();mapHeight>=n.initialMapHeight&&t>n.initialMapHeight&&t/n.initialMapHeight*n.initialMapWidth<i?(height=t,width=t/n.initialMapHeight*n.initialMapWidth):mapWidth>=n.initialMapWidth&&i>n.initialMapWidth&&i/n.initialMapWidth*n.initialMapHeight<t?(width=i,height=i/n.initialMapWidth*n.initialMapHeight):(width=n.initialMapWidth,height=n.initialMapHeight);r=(t-height)/2;r<25&&(r=25);$(n.map).css({width:width,height:height});$(n.image).css({width:width,height:height});$(n.map).css({top:r})}function fixLeftPane(){$(window).scrollTop()>$(".js-HomePage").height()?$(".js-LeftPane").css({position:"fixed",top:0}):$(".js-LeftPane").css({position:"absolute",top:0})}function moreOptions(){$(".js-homeTitle").addClass("has-moreOptions");$(".js-BackgroundImageSlider").addClass("has-moreOptions")}function scrollToListing(){$.smoothScroll({scrollTarget:".js-LeftPane",easing:"swing",speed:1200})}function nextRotatorPhoto(){$(".BackgroundImageSlider").each(function(n,t){var i=$(t),r=i.find("div.current"),u;u=r.attr("id")==i.find('div[class*="slide-"]').last().attr("id")?i.find('div[class*="slide-"]').first():r.next();i.find('div[class*="slide-"]').not(u).css("z-index",-1);u.css("z-index","").stop().fadeIn(1200,function(){u.addClass("current");r.removeClass("current");r.stop().hide()})})}var nzMap,ausMap;$(document).ready(function(){"use strict";$(".js-SearchBox").length>0&&moreOptions();var n=$("input[id$=AvailableFrom]").val()==="Any"?null:$("input[id$=AvailableFrom]").val(),t=$("input[id$=AvailableTo]").val()==="Any"?null:$("input[id$=AvailableTo]").val();$("#Dates").daterangepicker({startDate:n,endDate:t},function(n,t){$(this.triggerElement).hasClass("js-AdvancedSearchBox-dates")?datePickerCustomBehaviours.setSelectedDatesAdvanced(n,t,"Check-in","Check-out"):datePickerCustomBehaviours.setSelectedDates(n,t)})}),function(n){n.fn.rwdImageMaps=function(){var i=this,t;n(".js-HomePageMap-newZealandTab").on("click",function(){t()});n(".js-HomePageMap-australiaTab").on("click",function(){t()});n(".js-HomePageMap-pacificIslandsTab").on("click",function(){resizePacificIslandsMap()});n(".js-HomePageMap-worldTab").on("click",function(){t()});return t=function(){i.each(function(){if(typeof n(this).attr("usemap")!="undefined"){var i=this,t=n(i);n("<img />").load(function(){var r=t.attr("width"),u=t.attr("height"),f;r&&u||(f=new Image,f.src=t.attr("src"),r||(r=f.width),u||(u=f.height));n(".js-HomePageMap-newZealandTab > a").hasClass("is-active")?(centerMap(nzMap),resizeMapItems(nzMap.map,".mapHoverState",nzMap.regionX,nzMap.regionY,nzMap.regionWidth,nzMap.regionHeight,nzMap.scaleX(),nzMap.scaleY()),resizeMapItems(nzMap.map,".js-mapLabel",nzMap.labelX,nzMap.labelY,null,null,nzMap.scaleX(),nzMap.scaleY())):n(".js-HomePageMap-australiaTab > a").hasClass("is-active")&&(centerMap(ausMap),resizeMapItems(ausMap.map,".mapHoverState",ausMap.regionX,ausMap.regionY,ausMap.regionWidth,ausMap.regionHeight,ausMap.scaleX(),ausMap.scaleY()),resizeMapItems(ausMap.map,".js-mapLabel",ausMap.labelX,ausMap.labelY,null,null,ausMap.scaleX(),ausMap.scaleY()),n(ausMap.map).removeClass("visuallyHidden"));var e=t.width()/100,o=t.height()/100,s=t.attr("usemap").replace("#",""),i="coords";n('map[name="'+s+'"]').find("area").each(function(){var f=n(this),s,h,t;for(f.data(i)||f.data(i,f.attr(i)),s=f.data(i).split(","),h=new Array(s.length),t=0;t<h.length;++t)h[t]=t%2==0?parseInt(s[t]/r*100*e):parseInt(s[t]/u*100*o);f.attr(i,h.toString())})}).attr("src",t.attr("src"))}})},n(window).resize(t).trigger("resize"),this}}(jQuery);$(window).bind("load",function(){$(".js-BackgroundImageSlider .js-slide").addClass("preload");window.setInterval(function(){nextRotatorPhoto()},1e4);$.ajax({type:"GET",url:"/AJAX/HomepageMapView.aspx"}).done(function(n){$(".js-MapView").html(n);setupMap();$(".js-HomePage-DownBtn").show();$(".js-HomePage-DownBtn").click(scrollToListing);nzMap=new HomePageMap(".js-HomePageMap-newZealandMap",".js-newZealandMapImage",423,440);ausMap=new HomePageMap(".js-HomePageMap-australiaMap",".js-australiaMapImage",423,440);storeMapRegions(nzMap);storeMapRegions(ausMap);storeMapLabels(nzMap);storeMapLabels(ausMap);$("img[usemap]").rwdImageMaps()});$(".Page-Home").length>0&&$(".js-Header").sticky({topElement:".js-HomePage",positionOffset:-40,useElementHeight:!0});$(window).on("scroll",fixLeftPane);$(window).on("resize",fixLeftPane)})