$(function() {
	$("#Date").datepicker({ dateFormat: 'dd/mm/yy' });
	$(".Date").datepicker({ dateFormat: 'dd/mm/yy' });
	
	var navDuration = 150; //time in miliseconds
      var navJumpHeight = "20px";

	//$('.navigation li').hover(function() {
    //      $(this).animate({ marginLeft : "+="+navJumpHeight }, navDuration);            
    //  }, function() {
    //      $(this).animate({ marginLeft : "-="+navJumpHeight }, navDuration);
    //  });
});

$(function() {
	$("#tabs").tabs();
});

function showCalendar(pDate,pID)
{
	$('#cal-'+pID).load('scripts/calendar.php', { RoomID: pID , Date: pDate });
}

function skipCalendar(pID)
{
	pDate = document.getElementById('Date-'+pID).value;
	$('#cal-'+pID).load('scripts/calendar.php', { RoomID: pID, Date: pDate });
}

function reload(pID,pDate)
{
	i = 1;
	while(i<=pID)
	{
		$('#cal-'+i).load('scripts/calendar.php', { RoomID: pID, Date: pDate });
		i++;
	}
}

function setDate(pDate,pTextDate,pMaxNights,pRoom,pDayNum,pMinStay,pOffer,pBreakfast,pPrice)
{
	var StartDate = pTextDate;
	var Room = pRoom;

	pCurrentDate = document.getElementById('Date-'+pRoom).value;
	var dates = pCurrentDate.split('/');
	var pResetDate = dates[2]+"-"+dates[1]+"-"+dates[0];

	document.getElementById('Arrival').innerHTML = pTextDate;
	document.getElementById(pRoom+'_CheckIn').innerHTML = "<br /><br />Your Chosen Check In Date: "+StartDate+" (<a href=\"javascript:showCalendar('"+pResetDate+"','"+pRoom+"');\">Click to Change</a>)";
	
	if(pMinStay>pMaxNights)
	{
		i=1;
	}
	else
	{
		i=pMinStay;
	}
	
	var pOptions = '';
	
	if(pMaxNights=='Please Call')
	{
		pOptions = "<option value='Please Call'>Please Call</option>";
	}
	else
	{
		while(i<=pMaxNights)
		{
			pOptions = pOptions+"<option value='"+i+"'>"+i+"</option>";
			i++;
		}
	}
	
	f_br = '';
	f_wi = '';
	
	if(pBreakfast == 'NoBreakfast'){
		alert('Breakfast is limited to cereals, toast and preserves on this day.  Apologies for any inconvenience.');	
	}else{
	
		if(pOffer == 'Breakfast'){
			if(pPrice<='55.00'){
				alert('Special Offer: Free Full English Breakfast with this Booking! (On Stays of 3 Nights or Longer)');
			}else{
				alert('Special Offer: Free Full English Breakfast with this Booking!');
			}
			f_br = 1;
			f_wi = 0;
			document.getElementById('Form_'+pRoom+'_Offer').value = 'Breakfast';
		}
		
		if(pOffer == 'Wine'){
			alert('Special Offer: Bottle of Wine with this Booking!');
			f_wi = 1;
			f_br = 0;
			document.getElementById('Form_'+pRoom+'_Offer').value = 'Wine';
		}
	
	}
	
	document.getElementById(pRoom+'_Nights').innerHTML = "<div class='BookingBlock'>2.  How many nights would you like to stay:<br /><select id='"+pRoom+"_NightsStay' onchange=\"javascript:showNights("+pRoom+","+pMinStay+","+pRoom+","+pPrice+");\"><option value=''>Please Select</option>"+pOptions+"</select><br /><br />Your Chosen Check Out Date: <span id='DepartureDate'></span></div>";
	document.getElementById(pRoom+"_"+pDayNum).className = 'num_container start';
	
	document.getElementById('Form_'+pRoom+'_StartDate').value = pDate;
	document.getElementById('Form_'+pRoom+'_RoomID').value = pRoom;
	document.getElementById('Form_'+pRoom+'_StartDay').value = pDayNum;
	
	$('#cal-'+pRoom+' .num_container a').removeAttr("href");
}

function showNights(pRoom,pMinStay,pID,pPrice)
{
	$('.num_container').removeClass('start');
	
	pNights = document.getElementById(pRoom+'_NightsStay').value - 0;
	pStartDay = document.getElementById('Form_'+pRoom+'_StartDay').value - 0;
	pRoom = document.getElementById('Form_'+pRoom+'_RoomID').value;

	if(pNights>=1 && pNights<=21)
	{
		pTotal = pStartDay+pNights;
		i = pStartDay;
		while(i <=(pTotal-1))
		{
			document.getElementById(pRoom+"_"+i).className = 'num_container start';
			i++;
		}
		
		document.getElementById(pRoom+'_Next').style.display = 'block';
		document.getElementById('Form_'+pRoom+'_Nights').value = pNights;
		
		if(pRoom==9){
			var Children_Drop = "<br />Children<br /><select name='Children'><option value='0'>0</option><option value='1'>1</option><option value='2'>2</option></select>";
		}else{
			var Children_Drop = '';
		}
		
		if(f_wi == 1){
			document.getElementById(pRoom+'_Extras').innerHTML = "<div class='BookingBlockLarge'>3.  Extras<br />Full English Breakfast <input type=\"radio\" name=\"Breakfast\" value=\"Full\" /><br /><small>(&pound;7.50 per person, per night)</small><br />Budget Breakfast <input type=\"radio\" name=\"Breakfast\" value=\"Budget\" /><br /><small>(&pound;3.00 per person, per night)</small><br />Flowers &amp; Champagne <input type=\"checkbox\" name=\"Champagne\" /><br /><small>(&pound;45.00)</small><br />Bottle of Wine <input type=\"checkbox\" name=\"Wine\" checked disabled /><br /><small>(<strong>FREE!</strong>)</small>"+Children_Drop+"</div>";	
		}else if((f_br == 1 && pPrice=='55.00' && pNights>2) || (f_br == 1 && pPrice>'55.00' && pNights>0)){
			document.getElementById(pRoom+'_Extras').innerHTML = "<div class='BookingBlockLarge'>3.  Extras<br />Full English Breakfast <input type=\"radio\" name=\"Breakfast\" value=\"Full\" checked disabled/><br /><small>(<strong>FREE!</strong>)</small><br />Flowers &amp; Champagne <input type=\"checkbox\" name=\"Champagne\" /><br /><small>(&pound;45.00)</small><br />Bottle of Wine <input type=\"checkbox\" name=\"Wine\" /><br /><small>(&pound;10.00)</small>"+Children_Drop+"</div>";	
		}else{
			document.getElementById(pRoom+'_Extras').innerHTML = "<div class='BookingBlockLarge'>3.  Extras<br />Full English Breakfast <input type=\"radio\" name=\"Breakfast\" value=\"Full\" /><br /><small>(&pound;7.50 per person, per night)</small><br />Budget Breakfast <input type=\"radio\" name=\"Breakfast\" value=\"Budget\" /><br /><small>(&pound;3.00 per person, per night)</small><br />Flowers &amp; Champagne <input type=\"checkbox\" name=\"Champagne\" /><br /><small>(&pound;45.00)</small><br />Bottle of Wine <input type=\"checkbox\" name=\"Wine\" /><br /><small>(&pound;10.00)</small>"+Children_Drop+"</div>";
		}
		
		document.getElementById('Form_'+pRoom+'_Nights').value = pNights;
		
		pDate = document.getElementById('Form_'+pRoom+'_StartDate').value;
		$('#Departure').load('scripts/checkoutday.php', { Date: pDate , Nights: pNights});
		$('#DepartureDate').load('scripts/checkoutday.php', { Date: pDate , Nights: pNights});
	}
	else
	{
		alert('Minimum Stay of '+pMinStay+' Nights Required');
		pDate = '';
		showCalendar(pDate,pID);
	}
}

function clearBooking(pID,pDate)
{	
	var dates = pDate.split('/');
	var pDate = dates[2]+"-"+dates[1]+"-"+dates[0];
	$('#cal-'+pID).load('scripts/calendar.php', { RoomID: pID, Date: pDate });
}



function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();


jQuery(document).ready(function() {
	
	$("#Webcam").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 780,
		'height'			: 700,
		'scrolling'   		: 'no'
	});
	
	$("#Webcam2").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 780,
		'height'			: 700,
		'scrolling'   		: 'no'
	});
	
	$("#BookingInstructions").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 800,
		'height'			: 400,
		'scrolling'   		: 'no'
	});
	
	$(window).load(function() {
		$('#slider').nivoSlider();
	});

});



