$(function(){function t(n,t){var i=$("#HouseID").val();$.ajax({url:"/api/HouseAvailability/"+i+"/"+n.year()+"/"+(n.month()+1),type:"GET",contentType:"application/json;charset=utf-8",async:!1,success:function(n){t.blockedDates=n}})}function n(n){n.on("onBeforeUpdate",function(n,i){t(i.picker.leftCalendar.month,i.picker.leftCalendar),t(i.picker.rightCalendar.month,i.picker.rightCalendar)});n.on("onAfterDateClick",function(n,t){var i=function(){for(var n=0,r=t.picker.leftCalendar.blockedDates,i=t.picker.leftCalendar.selectedDates;n<=i.length;n++)if(i[n]&&r[n]&&!(n===i.length-1))return!0;for(n=0,r=t.picker.rightCalendar.blockedDates,i=t.picker.rightCalendar.selectedDates;n<=i.length;n++)if(i[n]&&r[n]&&!(n===i.length-1))return!0;return!1}();i?($(".js-bookingForm-bookedDatesValidation").show(),$(".js-checkinDate, .js-checkoutDate").addClass("validation-date--fail")):($(".js-bookingForm-bookedDatesValidation").hide(),$(".js-checkinDate, .js-checkoutDate").removeClass("validation-date--fail"))})}function r(n){n.preventDefault();var t=$(n.target);t.is("DIV.js-Shortlist")&&(t=t.parent()),jQuery.get(t.attr("href"),{ajax:"true"},i)}function i(n){var i=$("A.Button--shortlist.js-shortlist"),t=$("A.js-Shortlist");i.attr("href",n.url),t.attr("href",n.url),n.url.search("Remove")>0?(i.html("- SHORTLIST").attr("title","Click to remove from shortlist"),t.removeClass("Shortlist-add").addClass("Shortlist-remove").attr("title","Click to remove from shortlist")):(i.html("+ SHORTLIST").attr("title","Click to add to shortlist"),t.removeClass("Shortlist-remove").removeClass("Shortlist-remove").addClass("Shortlist-add").attr("title","Click to add to shortlist")),hhLib.UpdateShortlistCount(n.count)}$(".bookingDates .daterangepickertrigger").find('input[type="text"]').prop("readonly",!0),CreateCollapseToggler=function(n){return function(){var i=n,t=i.closest(".js-collapsible-section");AnimateSection(t)}},AnimateSection=function(n){n.find(".section-content").toggle("blind"),n.hasClass("collapsed")?(n.removeClass("collapsed").addClass("open"),hhLib.ScrollToAnchor(n.attr("id")),n.find(".section-content").find(".js-gmap").length>0&&google.maps.event.trigger(map,"resize")):n.removeClass("open").addClass("collapsed")},$(".collapsible-header").each(function(n,t){t=$(t),t.click(CreateCollapseToggler(t)).attr("title","Click to show/hide this section")}),$(".Booking-section .daterangepickertrigger").click(function(t){var i=hhLib.houseLib.GetListingHeaderBookingDates(),r;i.departDate==""&&(i.departDate=null),i.arriveDate==""&&(i.arriveDate=null),r=$(t.target).closest(".js-DateRangePicker"),n($(r)),$(r).daterangepicker({format:"YYYY-MM-DD",showPlaceholderTextOnOpen:!1,startDate:i.arriveDate,endDate:i.departDate,returnFormat:"plain",opens:"left"},hhLib.houseLib.DatePickerCallback)}),$(".bookingDates .daterangepickertrigger").click(function(t){var i=hhLib.houseLib.GetListingHeaderBookingDates(),r;i.departDate==""&&(i.departDate=null),i.arriveDate==""&&(i.arriveDate=null),r=$(t.target).closest(".js-DateRangePicker"),n($(r)),$(r).daterangepicker({format:"YYYY-MM-DD",showPlaceholderTextOnOpen:!1,startDate:i.arriveDate,endDate:i.departDate,returnFormat:"plain",opens:"top"},hhLib.houseLib.DatePickerCallback)}),$(".ReadMore, .ShowLess").click(function(n){var t=$(n.target);t.hasClass("ReadMore")&&($(".description.short").toggle("blind"),$(".description.full").toggle("blind")),t.hasClass("ShowLess")&&($(".description.full").toggle("blind"),$(".description.short").toggle("blind"))}),$(".Reviews .ShowAll").click(function(n){n.preventDefault(),$(".ListingComment.hiddenComment").removeClass("hiddenComment"),$(n.target).hide()}),$(".bookingView .checkinday").change(function(){hhLib.houseLib.SetBookingDates()}),$(".bookingView .CheckInMonth").change(function(){hhLib.houseLib.SetBookingDates()}),$(".bookingView .BookingDuration").change(function(){hhLib.houseLib.SetBookingDates()}),$(".js-listingHeaderGuestsdropdown").select2({minimumResultsForSearch:1e3,dropdownCssClass:"noPaddingDropdown"}),hhLib.houseLib={SetBookingDates:function(){var f=$(".bookingView .checkinday").val(),e=$(".bookingView .CheckInMonth").val(),u,r,o=parseInt($(".bookingView .BookingDuration").val()),t,i,n;e!=""&&(t=e.split(":"),u=parseInt(t[0]),r=parseInt(t[1])),f!=""&&u!=""&&r!=""&&(i=moment(new Date(r,u-1,f)),n=moment(i),n.add("days",o),hhLib.houseLib.DatePickerCallback(i.toDate(),n.toDate()))},getBookingArriveDay:function(){return $(".bookingView .checkinday")},getBookingMonthYear:function(){return $(".bookingView .CheckInMonth")},getBookingDuration:function(){return $(".bookingView .BookingDuration")},getArriveDD:function(){return $(".CheckinContainer .date-dd")},getArriveMMM:function(){return $(".CheckinContainer .date-month")},getArriveYYYY:function(){return $(".CheckinContainer .date-year")},getArriveDate:function(){return $(".CheckinContainer .rawdate")},getDepartDD:function(){return $(".CheckoutContainer .date-dd")},getDepartMMM:function(){return $(".CheckoutContainer .date-month")},getDepartYYYY:function(){return $(".CheckoutContainer .date-year")},getDepartDate:function(){return $(".CheckoutContainer .rawdate")},DatePickerCallback:function(n,t){n=new Date(n),t=new Date(t),hhLib.houseLib.getArriveDate().val(""),hhLib.houseLib.getDepartDate().val(""),hhLib.houseLib.getArriveDD().html(n.getDate()),hhLib.houseLib.getArriveMMM().html(hhLib.monthAbbrevs[n.getMonth()].toUpperCase()),hhLib.houseLib.getArriveYYYY().html(n.getFullYear()),hhLib.houseLib.getArriveDate().val(n.toString()),hhLib.houseLib.getDepartDD().html(t.getDate()),hhLib.houseLib.getDepartMMM().html(hhLib.monthAbbrevs[t.getMonth()].toUpperCase()),hhLib.houseLib.getDepartYYYY().html(t.getFullYear()),hhLib.houseLib.getDepartDate().val(t.toString()),$(".FormContainer INPUT.ArriveDate").val(moment(n).format("ddd Do MMM YYYY")),$(".FormContainer INPUT.DepartDate").val(moment(t).format("ddd Do MMM YYYY")),$("INPUT.js-hidden-arriveDate").val(moment(n).format("YYYY-MM-DD")),$("INPUT.js-hidden-departDate").val(moment(t).format("YYYY-MM-DD")),$(".ArriveDateHidden").val(n.toString()),$(".DepartDateHidden").val(t.toString())},GetListingHeaderBookingDates:function(){var n={arriveDate:"",departDate:""},i=hhLib.houseLib.getArriveDate().val(),t=hhLib.houseLib.getDepartDate().val();return i!=""&&(n.arriveDate=new Date(i)),t!=""&&(n.departDate=new Date(t)),n}},$(".Button.Button--enquire, .Button.Button--book").not(".bookingView .Button.Button--book, .enquiryView .Button--enquire").click(function(n){n.preventDefault();var t=$(n.target);$(".Forms.js-collapsible-section.collapsed").length==1&&AnimateSection($(".Forms.js-collapsible-section")),hhLib.ScrollToAnchor("booking-enquiry-form")}),hhLib.AttachHandlerIfCookiesAreOn($(".Button--shortlist.js-shortlist, A.js-Shortlist"),r)})