$(document).ready(function() {
	$("#navigation .haschildren ul").each(function() {
		$(this).siblings("a").before($(this).remove());		
	});
	
	$("#navigation a.nav").hover(function() {
		$(this).addClass("nav_h");
	},
	function () {
		$(this).removeClass("nav_h");
	});
	
	$("#navigation .haschildren").each(function() {
		//save the ul child's initial height to the li.children's 'data'
		$(this).data("orig_height",$(this).children("ul").css("height"));
		
	}).hover(function() {
		//on
		var orig_height = $(this).data("orig_height");
		$(this).children("a").unbind().addClass("nav_h");
		$(this).children("ul").stop().animate({
			"height":orig_height
		},220);
	},
	function() {
		// off
		$(this).children("a").removeClass("nav_h");
		$(this).children("ul").stop().animate({
			"height":0
		},100);
	});
	
	// hide the child menu
	$("#navigation .haschildren ul").css("height",0);
	
	
	// setting up the booking form
	$("#form_type").change(function() {
		//alert($(this).val());
		var val = $(this).val();
		if (val == 0) {
			$("#form_airport").hide(50,function(){
				$("#form_attractions").hide(50,function(){
					$("#form_general").show(100);
				});
			});
		} else if (val == 1 || val == 3) {
			$("#form_general").hide(50,function(){
				$("#form_attractions").hide(50,function(){
					$("#form_airport").show(100);
				});
			});
		} else if (val == 2) {
			$("#form_airport").hide(50,function(){
				$("#form_general").hide(50,function(){
					$("#form_attractions").show(100);
				});
			});
		}
	}).change();
	
	// setting up datepickers on booking form
	$(".datepicker").datepicker({
		dateFormat: 'dd MM yy'
	});
	
	// form validation for booking/contact page
	$("#form").submit(function() {
		
		if ($("[name='full_name']").val() != ""     // if name is not blank
		 || $("[name='accommodation']").val() != "" // if accommodation is not blank
		 || $("[name='email']").val() != ""         // if email is not blank
		 || $("[name='phone']").val() != "") {      // if phone is not blank
			return true;
		 } 
		 
		if ($("#form_type").val() == 0) {
			if ($("[name='comment_general']").val() == ""){
				alert("Please enter the details for your enquiry.");
				return false;
			} else {
				return true;
			}			
		} else if ($("#form_type").val() == 1 || $("#form_type").val() == 3) {
			if ($("[name='airport']").val() != ""
			 || $("[name='departure_date']").val() != ""
			 || $("[name='departure_time']").val() != ""
			 || $("[name='departure_number']").val() != ""
			 || $("[name='departure_adults']").val() != ""
			 || $("[name='departure_children']").val() != ""
			 || $("[name='arrival_date']").val() != ""
			 || $("[name='arrival_time']").val() != ""
			 || $("[name='arrival_number']").val() != ""
			 || $("[name='arrival_adults']").val() != ""
			 || $("[name='arrival_children']").val() != ""
			 || $("[name='comment_airport']").val() != "") {
				return true;
			 } else {
				alert("Please enter the details for your Airport Transfer.");
				return false;				
			 }
		} else if ($("#form_type").val() == 2) {
			if ($("[name='attraction']").val() != ""
			 || $("[name='attraction_date']").val() != ""
			 || $("[name='attraction_adults']").val() != ""
			 || $("[name='attraction_children']").val() != ""
			 || $("[name='comment_attraction']").val() != "") {
				return true;
			 } else {
				alert("Please enter the details for your Attraction Transfer.");
				return false;
			 }
		} else {
			// unknown form type, return false
			return false;
		}
	});
});







































