var calendarStart;var firstPossibleDate;var lastPossibleDate;var currentSlotStart;var currentSlot;var animating;var today=new Date();today.setHours(0,0,0,0);var calendarWidth;var dayWidth=13;var aid;var grabX=0;var mouseX=0;var grabbed=false;var lastDuration=0;var calendarLeft=0;var calendarRight=0;var leftOffset=0;var updating=false;function SetupCalendar(c,b,a){firstPossibleDate=(c!=null?c:today);lastPossibleDate=(b!=null?b.dateAdd("d",1):null);calendarStart=today.dateAdd("d",-1);calendarWidth=a;resetCalendar();showCalendar();}function resetCalendar(){lastDuration=(holidayCriteria.Duration.length>0?holidayCriteria.Duration[0]:7);currentSlot=null;calendarLeft=0;}function showCalendar(){var a=document.getElementById("calendar");var b=[];if(calendarSlots.length==1&&calendarSlots[0].type=="U"){b.push("<div class='no-online'>Sorry - we don't have online availability for a "+lastDuration+" night holiday in this accommodation.</div>");a.innerHTML=b.join("");}else{b.push('<div id="previous-month"><a href="Javascript:moveDays(-calendarWidth)" title="Show earlier dates"></a></div>');b.push('<div id="next-month"><a href="Javascript:moveDays(calendarWidth)" title="Show later dates"></a></div>');b.push('<div id="booking-link"></div>');b.push('<div id="calendar-dates"></div>');a.innerHTML=b.join("");calendarStart=today.dateAdd("d",-1);var b=[];b.push('<div id="calendar-days">');b.push(calendarStart.getCalendar(calendarSlots).join(""));b.push('<div id="booking-window">');b.push('<div id="booking-lens"><a href="#" id="booking-lens-link" onclick="return book(this)">');b.push('<img id="booking-lens-image" src="/images/slider.png" width="100%" height="100%" title="Book now"/></a></div>');b.push('<div id="booking-cost"></div>');b.push('<div id="calendar-left"><a href="Javascript:moveToPreviousSlot()" title="Earlier booking"></a></div>');b.push('<div id="calendar-right"><a href="Javascript:moveToNextSlot()" title="Later booking"></a></div>');b.push("</div>");b.push("</div>");var c=document.getElementById("calendar-dates");c.innerHTML=b.join("");document.getElementById("booking-window").style.left=dayWidth+"px";document.getElementById("booking-window").style.width=((lastDuration+1)*dayWidth)-2+"px";animateCalendar(calendarLeft,0,true);if(updating){moveToVisibleSlot(calendarStart.dateAdd("d",0-calendarLeft),calendarStart.dateAdd("d",calendarWidth-calendarLeft-1));updating=false;}else{moveToFirstSlot(firstPossibleDate,(calendarLeft==0));}}var b=[];b.push("Availability for ");b.push("<a id='duration-3' href='Javascript:updateCalendar(3)'>3</a>");b.push("<a id='duration-4' href='Javascript:updateCalendar(4)'>4</a>");b.push("<a id='duration-7' href='Javascript:updateCalendar(7)'>7</a>");b.push("<a id='duration-14' href='Javascript:updateCalendar(14)'>14</a>");b.push("<a id='duration-21' href='Javascript:updateCalendar(21)'>21</a>");b.push(" nights");document.getElementById("calendar-title").innerHTML=b.join("");document.getElementById("duration-3").style.backgroundColor="#DDDDDD";document.getElementById("duration-4").style.backgroundColor="#DDDDDD";document.getElementById("duration-7").style.backgroundColor="#DDDDDD";document.getElementById("duration-14").style.backgroundColor="#DDDDDD";document.getElementById("duration-21").style.backgroundColor="#DDDDDD";document.getElementById("duration-"+lastDuration).style.backgroundColor="white";return(a.style.display!="none");}function updateCalendar(a){updating=true;lastDuration=a;currentSlot=null;GetAvailability(aid,a,holidayCriteria.StartDate,holidayCriteria.EndDate,holidayCriteria.Campaign,holidayCriteria.MaxPrice);}Date.prototype.getCalendar=function(c){var n=[];var h=document.getElementById("calendar-days");if(c.length==1&&c[0].type=="U"){}else{n.push("<ul>");var k=this;var a=k.getDate();var f;var l=0;var e=500;calendarSlots=c;calendarRight=0;for(var g=1;g<=e;g++){f=false;var d;var m;for(var b=l;b<c.length;b++){m=c[b];while(b<c.length-1&&DateDiff(k,c[b+1].startDate)<=0){b++;m=c[b];}d=m.type;if(DateDiff(k,m.startDate)==0){if(m.type=="U"){e=g+30;}else{f=true;}break;}else{if(DateDiff(k,m.startDate)<0&&DateDiff(k,m.endDate)>=0){break;}else{if(DateDiff(k,m.startDate)>0){d=null;break;}}}}l=b;if(f){switch(d){case"A":if(holidayCriteria.Campaign>0){n.push('<li title="'+k.toDateString()+' is an available start day, but it is not part of this offer" onclick="moveToSlot('+b+', true)" class="out-of-bounds-start">');break;}case"C":n.push('<li title="'+k.toDateString()+' is an available start day" onclick="moveToSlot('+b+', true)" class="start-day">');break;case"O":if(holidayCriteria.Campaign>0){n.push('<li title="'+k.toDateString()+' is an available start day, but it is not part of this offer" onclick="moveToSlot('+b+', true)" class="out-of-bounds-start">');break;}case"X":n.push('<li title="'+k.toDateString()+' is an available start day, but it is outside your requested dates" onclick="moveToSlot('+b+', true)" class="out-of-bounds-start">');break;case"M":n.push('<li title="'+k.toDateString()+' is an available start day, but it is over your requested budget" onclick="moveToSlot('+b+', true)" class="out-of-bounds-start">');break;}}else{switch(d){case"A":if(holidayCriteria.Campaign>0){n.push('<li title="'+k.toDateString()+' is available, but it is not part of this offer" onclick="moveToSlot('+b+', true)" class="out-of-bounds">');break;}case"C":n.push('<li title="'+k.toDateString()+' is available" onclick="moveToSlot('+b+', true)" class="available">');break;case"O":if(holidayCriteria.Campaign>0){n.push('<li title="'+k.toDateString()+' is available, but it is not part of this offer" onclick="moveToSlot('+b+', true)" class="out-of-bounds">');break;}case"X":n.push('<li title="'+k.toDateString()+' is available, but it is outside your requested dates" onclick="moveToSlot('+b+', true)" class="out-of-bounds">');break;case"M":n.push('<li title="'+k.toDateString()+' is available, but it is over your requested budget" onclick="moveToSlot('+b+', true)" class="out-of-bounds">');break;case"U":n.push("<li title=\"Sorry, we don't have availability information for "+k.toDateString()+'" class="dunavailable">');break;default:n.push('<li title="'+k.toDateString()+' is not available" class="unavailable">');break;}}n.push('<span class="day">'+k.getDayOfWeek()+"</span><br/>");n.push(a);if(a==1){n.push('<div class="month">');n.push(k.getMonthName());n.push(" ");n.push(k.getFullYear());n.push('</div><div class="first"></div>');}n.push("</li>");k=this.dateAdd("d",g);a=k.getDate();calendarRight++;}n.push("</ul>");}return n;};function moveToFirstSlot(d,a){var b;for(b=0;b<calendarSlots.length;b++){var c=calendarSlots[b];if(c.startDate>=d&&c.type!="U"){moveToSlot(b,a,0);break;}}startAnimation();endAnimation();if(b<calendarSlots.length){return true;}else{return false;}}function moveToVisibleSlot(d,b){if(currentSlot&&calendarSlots[currentSlot].startDate>d.dateAdd("d",1)&&calendarSlots[currentSlot].endDate.dateAdd("d",1)<b&&calendarSlots[currentSlot].type!="U"){return;}var a;for(a=0;a<calendarSlots.length;a++){var c=calendarSlots[a];if(c.startDate>d.dateAdd("d",1)&&c.endDate<b&&c.type!="U"){endAnimation();moveToSlot(a,true,0);return true;break;}}return false;}function findFirstSlot(c){var a;for(a=0;a<calendarSlots.length;a++){var b=calendarSlots[a];if(b.startDate>=c&&b.type!="U"){return a;}}return -1;}function moveToSlot(h,g,j){if(j==null){j=500;}if(h<0||h>calendarSlots.length-1){return;}if(animating){return;}var k=calendarSlots[h];var i=DateDiff(calendarStart,k.startDate);var c=DateDiff(calendarStart,k.endDate);if(g){if(calendarLeft+i<1){animateCalendar(1-i,j,false);}else{if(c+calendarLeft+2>calendarWidth){animateCalendar(calendarWidth-c-2,j,false);}}}else{if((calendarLeft+i<1)&&(calendarLeft+c>0)){animateCalendar(1-i,j,false);}else{if((calendarLeft+i<calendarWidth)&&(calendarLeft+c>calendarWidth-2)){animateCalendar(calendarWidth-c-2,j,false);}}}animateBookingWindow(i*dayWidth,j);var b=document.getElementById("booking-cost");var d=[];if(k.basePrice>k.finalPrice){d.push("<span class='was'>&pound;"+Math.round(k.basePrice)+"</span>");}d.push((k.finalPrice>0?"&pound;"+Math.round(k.finalPrice):"POA")+"</a>");b.innerHTML=d.join("");var d=[];d.push("booking.aspx?aid=");d.push(aid);d.push("&start=");d.push(k.startDate.getDateString());d.push("&duration=");d.push(k.duration);d.push("&occ=");d.push(holidayCriteria.People);d.push("&searchStart=");d.push(firstPossibleDate.getDateString());if(lastPossibleDate!=null){d.push("&searchEnd=");d.push(lastPossibleDate.getDateString());}var e=d.join("");var a=document.getElementById("booking-lens-link");a.href=e;var d=[];d.push("<a href='");d.push(e);d.push("' onclick='return book(this)' rel='nofollow' ");d.push("title='Book now'>");d.push("Book now >");d.push("</a>");var f=document.getElementById("booking-link");f.innerHTML=d.join("");currentSlotStart=k.startDate;currentSlot=h;}function book(a){if(window==window.top){return hs.htmlExpand(a,{objectType:"iframe",width:900,height:600});}else{return true;}}function moveToNextSlot(){moveToSlot(currentSlot+1,true);}function moveToPreviousSlot(){moveToSlot(currentSlot-1,true);}function moveDays(a){animateCalendar(calendarLeft-a,1000,true);}function animateBookingWindow(b,a){var c=document.getElementById("booking-window");var d=parseInt(c.style.left.replace(/px/,""));if(a==0){c.style.left=b+"px";}else{Motion(c,d,b,"easeOutBounce",a);}}function animateCalendar(b,h,e){if(b>0){b=0;}if(b<(calendarRight*-1)+calendarWidth){b=(calendarRight*-1)+calendarWidth;}if(e&&currentSlot!=null){var i=calendarSlots[currentSlot];var f=DateDiff(calendarStart,i.startDate);var d=DateDiff(calendarStart,i.endDate);if(b+f<1&&b+d>0){b=1-f;}else{if(b+f<calendarWidth&&b+d>calendarWidth-1){b=calendarWidth-d-1;}}}var c=document.getElementById("calendar-days");var a=parseInt(c.style.left.replace(/px/,""));if(isNaN(a)){a=0;}calendarLeft=b;var g=Math.round(calendarLeft*dayWidth);if(h==0){c.style.left=g+"px";}else{Motion(c,a,g,"easeInOutBack",h);}}