	var STORE_stay_price_gbp = 0; var STORE_stay_price_usd = 0; var STORE_stay_price_eur = 0;
	STORE_extra_gbp = new Array();
	STORE_extra_usd = new Array();
	STORE_extra_eur = new Array();

$(document).ready(function(){

/* GALLERY */
	    $("#img-thumb-container img").fadeTo("normal",0.5);
		$("#img-thumb-container img:first").fadeTo("normal",1);

		$("#img-thumb-container img").click(function(){

			var large_path = $(this).attr("src");
			var large_title = $(this).attr("title");
			var description = $(this).attr("title");
			
			$("#img-large img").fadeOut("slow",function(){
				$("#img-large img").attr({ src: large_path});
				$("#img-large img").attr({ title: large_title});
				$("#img-description").html(description); return false;
			});
			$("#img-large img").fadeIn("slow");
			
			$("#img-thumb-container img").fadeTo("slow",0.5);
			$(this).fadeTo("slow",1);
		});

/*	BED - BATH */
		$(".bed-bath-info").hide();
		
		$("#bed-bath-sleeps").click(function () {
		    if ($(".bed-bath-info").is(":hidden"))
				{
					$(".bed-bath-info").fadeIn("slow");
		      	} else {
		      		$(".bed-bath-info").fadeOut("slow");
		      	}
		});

/* TABS */
		$("#tabs").tabs();

/* PRICES AND BOOKING */	

	//DATEPICKER	
		$('#arrival-date').datepicker({
			dateFormat: 'dd/mm/yy',
			showButtonPanel: true,
			beforeShow: custom_range,
			beforeShowDay: set_booked_days
		});
		
		$('#departure-date').datepicker({
			dateFormat: 'dd/mm/yy',
			showButtonPanel: true,
			beforeShow: custom_range,
			beforeShowDay: set_booked_days
		});
			
	//DEPARTURE DISABLE	
		if($("#departure-date").attr('value') == "")
		{$("#departure-date").datepicker("disable");}
		
		$("#arrival-date").change(function(){
			if($("#arrival-date").attr('value')=="")
			{
				$("#departure-date").datepicker("disable");
			} else {
				$("#departure-date").datepicker("enable");
			}
		});

	//MIN & MAX VALUES
		function custom_range(input)
		{
			return {
				minDate: (input.id == 'departure-date' ? $('#arrival-date').datepicker('getDate') : 0),
				maxDate: (input.id == 'arrival-date' ? $('#departure-date').datepicker('getDate') : null)
			};
		}

	//BOOKINGS
		function value_append(value)
		{
			var date1 = value.toString();
			if(date1.length == 1){date1 = "0" + date1;}
			return date1;
		}
		
		function set_booked_days(date)
		{
			var is_booked = false;
			if (dates_booked != null)
			{
				for (i = 0; i < dates_booked.length; i++)
				{
					var arrival_month = value_append(dates_booked[i][1] - 1);
					var arrival_day = value_append(dates_booked[i][2]);
					var departure_month = value_append(dates_booked[i][4] - 1);
					var departure_day = value_append(dates_booked[i][5]);
					var value_month = value_append(date.getMonth());
					var value_day = value_append(date.getDate());
										
					var arrival_date = dates_booked[i][0].toString() + arrival_month + arrival_day;
					var departure_date = dates_booked[i][3].toString() + departure_month + departure_day;
					var new_date = date.getFullYear() + value_month + value_day;
					
					if((new_date >= arrival_date)&&(new_date <= departure_date))
					{
						is_booked = true;
					}
				}	
			}

			if(is_booked)
			{
				return [false, 'booked'];	
			} else {
				return [true, ''];
			}
		}

	//GET QUOTE		
		$("#arrival-date").change(function(){
			if(($("#arrival-date").attr('value')!="")&&($("#departure-date").attr('value')!="")){updateQuote();}
		});
		$("#departure-date").change(function(){
			if(($("#arrival-date").attr('value')!="")&&($("#departure-date").attr('value')!="")){updateQuote();}
		});
		
		function updateQuote()
		{
			$("#booking-loading").removeClass('hidden');
			$("#arrival-date").datepicker("disable");
			$("#departure-date").datepicker("disable");
			
			var arrival = $("#arrival-date").attr('value');
			var departure = $("#departure-date").attr('value');
			list_data = "property_id=" + property_id + "&arrival=" + arrival + "&departure=" + departure;
				$.ajax({
					type: "POST",
					url: "../propertytemplate/quote.php",
					data: list_data,
					dataType: "xml",
					success: function(xml)
					{
						var xml_confirm = "false";
						$(xml).find('result').each(function(){
							xml_confirm = $(this).find('confirm').text();
							var xml_conflict = $(this).find('conflict').text();
							var xml_nights = $(this).find('nights').text();
							var xml_gbp = $(this).find('gbp').text();
							var xml_usd = $(this).find('usd').text();
							var xml_eur = $(this).find('eur').text();
							
							if(xml_confirm == "true")
							{
								if(xml_conflict == "1")
								{
									alert("The dates you have entered conflict with a booking already made, please check the dates and try again.");
									document.getElementById("departure-date").value = "";
									document.getElementById("booking-nights").innerHTML = "";
									document.getElementById("booking-nights-hidden").value = "";
								} else {
									document.getElementById("booking-nights").innerHTML = xml_nights;
									document.getElementById("booking-nights-hidden").value = xml_nights;
									STORE_stay_price_gbp = xml_gbp
									STORE_stay_price_usd = xml_usd;
									STORE_stay_price_eur = xml_eur;
									display_prices();
								}
							} else {alert("Hmm an error has occured, please try again.");}
						});
						
						$("#booking-loading").addClass('hidden');
						$("#arrival-date").datepicker("enable");
						$("#departure-date").datepicker("enable");
					}
				});
		}
	
	//Display Prices
		$("#booking-currency-value").change(function(){display_prices();});
		$("#booking-currency-value").ready(function(){display_prices();});
		$(".booking-extra-qty-checkbox").click(function(){display_prices();});
		$(".booking-extra-qty-text").blur(function(){if(this.value == ""){this.value = "0"}display_prices();});
		
		
		function display_prices()
		{
			number_of_nights = document.getElementById("booking-nights").innerHTML;
			
			//Currency Symbol
			$(".booking-currency-symbol").each(function(i){
				var new_currency;
				if($("#booking-currency-value").attr('value') == "GBP"){new_currency = "&#163;";}
				if($("#booking-currency-value").attr('value') == "USD"){new_currency = "&#36;";}
				if($("#booking-currency-value").attr('value') == "EUR"){new_currency = "&#128;";}
				this.innerHTML = new_currency;
			});
			
			//Stay Price
			var new_stay_price;
			if($("#booking-currency-value").attr('value') == "GBP"){new_stay_price = STORE_stay_price_gbp;}
			if($("#booking-currency-value").attr('value') == "USD"){new_stay_price = STORE_stay_price_usd;}
			if($("#booking-currency-value").attr('value') == "EUR"){new_stay_price = STORE_stay_price_eur;}
			document.getElementById("booking-stay-price").innerHTML = new_stay_price;
			$("#booking-stayPrice-hidden").val(new_stay_price);
			
			
			//Extras
			extra_total = 0;
			$(".booking-extra-price").each(function(i){				
				new_extra_price = 0;
				new_extra_total = 0;
				
				if($("#booking-currency-value").attr('value') == "GBP"){new_extra_price = STORE_extra_gbp[i];}
				if($("#booking-currency-value").attr('value') == "USD"){new_extra_price = STORE_extra_usd[i];}
				if($("#booking-currency-value").attr('value') == "EUR"){new_extra_price = STORE_extra_eur[i];}
				this.innerHTML = new_extra_price;
				document.getElementById("booking-extra-price-" + i + "-hidden").value = new_extra_price;
				
				qty = $("#booking-extra-qty-" + i).attr('value');
				per = document.getElementById("booking-extra-per-" + i).innerHTML;
				
				if(qty == "on")
				{			
					if(document.getElementById("booking-extra-qty-" + i).checked == true)
					{
						
						if(per.match("Day"))
						{
							new_extra_total = new_extra_price * number_of_nights;
						} else if(per.match("Week"))
						{
							new_extra_total = (new_extra_price/7) * number_of_nights;
						} else {
							new_extra_total = new_extra_price;
						}
						
					} else {new_extra_total = 0;}
					
				} else {
					new_extra_total = qty * new_extra_price;
				}
				new_extra_total = new_extra_total.toFixed(2);
				document.getElementById("booking-extra-total-" + i).innerHTML = new_extra_total;
				document.getElementById("booking-extra-total-" + i + "-hidden").value = new_extra_total;
				
				extra_total = parseFloat(extra_total) + parseFloat(new_extra_total);
				extra_total = extra_total.toFixed(2);
			});
			document.getElementById("booking-extra-total").innerHTML = extra_total;
			$("#booking-extra-total-hidden").val(extra_total);
			
			//Total
			total_price = parseFloat(new_stay_price) + parseFloat(extra_total);
			total_price = total_price.toFixed(2);
			document.getElementById("booking-total").innerHTML = total_price;
			$("#booking-total-hidden").val(total_price);
		}
});
