//LOSE IE6 FLICKER BUG
//--------------------

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

//CALL FUNCTIONS ONDOMREADY
//-------------------------

$(document).ready(function() {
	//call functions on page load.
	
	$("#newsletter .text").attr("rel", $("#newsletter .text").val()).focus(function() {
		if ($(this).val() == $(this).attr("rel")) {
			$(this).val("");
		};
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val($(this).attr("rel"));
		};
	});
	$("#newsletter form").submit(function() {
		
		$.get($(this).attr("action"), {frmNewsletterEmail: $(".text", this).val()}, function(data) {
			alert(data);
		});		
		return false;
		
	});

});

function billingCountry(element) {

	if (element.value != "United Kingdom") {
		$("#lblCounty").html("County/State *");
		$("#lblPostcode").html("Postcode/Zipcode *");
		$("#frmAddressCopy").attr("disabled", true);
		$("select[name='bill_state']").css("display", "none").attr("name", "bill_state_select");
		$("input[name='bill_state_text']").css("display", "inline").attr("name", "bill_state");
	} else {
		$("#lblCounty").html("County *");
		$("#lblPostcode").html("Postcode *");
		$("#frmAddressCopy").attr("disabled", false);
		$("input[name='bill_state']").css("display", "none").attr("name", "bill_state_text");
		$("select[name='bill_state_select']").css("display", "inline").attr("name", "bill_state");
	};

};

function doToursForm(element) {

	var form = document.getElementById("toursForm");
		
	if (form.frmTypeOfTour.value == "group") {
		//group options
		
		if (element.name == "frmTypeOfTour" || element.name == "frmTime") {
			
			if (element.name == "frmTypeOfTour") {
				//element being changed was type of tour, amend the time drop down and number in party
				form.frmTime.options.length = 0;
				form.frmTime.options[0] = new Option("12 o'clock daytime tour", "12 o'clock daytime tour", false, false);
				form.frmTime.options[1] = new Option("7pm", "7pm", false, false);
				form.frmTime.options[2] = new Option("7.30pm", "7.30pm", false, false);
			};
			
			if (form.frmTime.value == "7pm" || form.frmTime.value == "7.30pm") {
				var minimum = 20;
			} else {
				var minimum = 12;
			};
			
			if (element.name == "frmTime" || element.name == "frmTypeOfTour") {
			
				form.frmNumberInParty.options.length = 0;
				for (var i=minimum; i<=34; i++) {
					form.frmNumberInParty.options[i-minimum] = new Option(i, i, false, false);
				};
				
			};
			
		};
		
		$("#mealOptions-individual").css("display", "none");		
		if (form.frmMealRequirements.value == "With meal") {
			$("#mealOptions-group").css("display", "block");
		} else {
			$("#mealOptions-group").css("display", "none");
		};	
		
		
	} else {
		//individual options
		
		if (element && element.name == "frmTypeOfTour") {
			//element being changed was type of tour, amend the time drop down and number in party
			form.frmTime.options.length = 0;
			form.frmTime.options[0] = new Option("12 noon", "12 noon", false, false);
			
			form.frmNumberInParty.options.length = 0;
			for (var i=0; i<=11; i++) {
				form.frmNumberInParty.options[i] = new Option(i+1, i+1, false, false);
			};
			
		};	
		
		$("#mealOptions-group").css("display", "none");
		if (form.frmMealRequirements.value == "With meal") {
			$("#mealOptions-individual").css("display", "block");
		} else {
			$("#mealOptions-individual").css("display", "none");
		};
		
	};
	
};

//CHECKOUT ADDRESS CLONING
//------------------------

function checkoutBillingToDelivery(check) {

	var form = document.getElementById("checkoutForm");
	
	if (check.checked == true) {
		
		form.ship_name.value = form.bill_name.value;
		form.ship_company.value = form.bill_company.value;
		form.ship_addr_1.value = form.bill_addr_1.value;
		form.ship_addr_2.value = form.bill_addr_2.value;
		form.ship_city.value = form.bill_city.value;
		form.ship_state.selectedIndex = form.bill_state.selectedIndex;
		//form.ship_country.value = form.bill_country.value;
		form.ship_post_code.value = form.bill_post_code.value;
		
		setTimeout("document.getElementById('frmAddressCopy').checked = false;", 500);
		
	};
	
};


function gallery(li, imageURL) {

	var imgID = document.getElementById("galleryImg");
	
	$("#gallery li").removeClass();
	$(li).addClass("active");
	
	imgID.src = imageURL;	
	
	return false;	
};