jQuery(document).ready(function() {
	// remove the first paragraph if empty
	/*
	if(jQuery("#the_content").length > 0) {
		if(jQuery.trim(jQuery("#the_content p:first").text()) == "") 
		jQuery("#the_content p:first").remove();
	}
	*/
	
	// putting the testimonial after the first paragraph
	if(jQuery("#testimonial").length > 0) {
		var testi = jQuery("#testimonial").html();
		jQuery("#testimonial").remove();
		if(jQuery("#the_content p:first").text() != "") {
			jQuery("#the_content p:first").after("<div id='testimonial'>"+testi+"</div>");
		}
		else {
			var i = 0;
			jQuery("#the_content p").each(function() {
				//if(i == 0 && $(this).text() == "") jQuery(this).remove();
				if(i==1) {
					jQuery(this).after("<div id='testimonial'>"+testi+"</div>");
				}
				if(i > 1) return false;
				i++;
			});
			
		}
	}
	
	// putting the image on the content (interior page) before the title
	/*
	if(jQuery("#the_content").length > 0) {
		if(jQuery("#the_content img:first").length > 0) {
			jQuery("img:first",jQuery("#thecontent")).hide();
		}
	}
	jQuery(".ngg-gallery-thumbnail img").show();
	*/
	
	// menu hover
	jQuery("#menu li").hover(function() {
		var theclass = $(this).attr("class");
		if(theclass.indexOf("last") == -1) $(this).addClass("lihover");
		else jQuery(this).addClass("lasthover");
	},function() {
		var theclass = $(this).attr("class");
		if(theclass.indexOf("last") == -1) $(this).removeClass("lihover");
		else jQuery(this).removeClass("lasthover");
	});
	jQuery(".page_item ul li").hover(function() {
		jQuery(this).removeClass("lihover");
	},function() {
		
	});
	
	// create last class on the menu
	jQuery("#menu li:last").addClass("last");
	
	// if the last list is the current state
	if(jQuery("#menu li").length > 0) {
		if(jQuery("#menu li:last").attr("class").indexOf("current") != -1) {
			jQuery("#menu li:last").removeClass("last");
			jQuery("#menu li:last").addClass("lastcurrent");
		}
	}
	
	// hide the unwanted submenu
	$("#left .page_item ul").each(function() {
		var theclass = $(this).parent("li").attr("class");
		
		if(theclass.indexOf("current_page_item") == -1) {
			$(this).hide();
		}
		if(theclass.indexOf("current_page_parent") == -1) {
			$(this).hide();
		}
		if(theclass.indexOf("current_page_item") != -1) {
			$(this).show();
		}
		if(theclass.indexOf("current_page_parent") != -1) {
			$(this).show();
		}
		
	});
	
	// button
	$(".sendbutton").attr("value","");
	
	// validation
	$("form#booking").submit(function() {
		var continueform = 1;
		$(".required").each(function() {
			var get_name = $(this).prev("label").text();
			get_name = get_name.replace("*","");
			if($(this).val() == "" || $(this).val() == null || $(this).val() == "0") {
				$(".error-info").empty().append("<p>Ooops, you forgot to fill in the "+get_name+"</p>");
					continueform = 0;
					$(this).focus();
					return false;
				
			}
			if($(this).attr("id") == "txtemailaddress") {
				valid_email = CheckEmail($(this).val());
				if(!valid_email) {
					$(".error-info").empty().append("<p>Ooops, your email address is not valid</p>");
					continueform = 0;
					$(this).focus();
					return false;
				}
			}
		});
		
		   if(($("select[@name=BED_TYPE]").val() == "3SG" ||
			$("select[@name=BED_TYPE]").val() == "3SH") &&
			($("input[@name=SHARE_NAME1]").val() == "" || $("input[@name=SHARE_NAME2]").val() == "")) {
			
				$(".error-info").empty().append("<p>3 Person Apt rooms can only be booked if you have 2 friends to share with already. Please enter your friends' names or select 2 Person Apt option.</p>");
				continueform = 0;
				$("input[@name=SHARE_NAME1]").focus();
				return false;
				
			}
		
		if(continueform) {
			if($("input[@name=TERMS]").attr("checked") == false) {
				alert("Please accept the Terms and Conditions by ticking the checkbox.");
				return false;
			}
			else return true;
		}
		else return false;
	});
	
	// datepicker
	if($(".dob").length > 0) {
		$(".dob").datepicker({
			mandatory: true,
			changeMonth: true,
			changeYear: true,
			maxDate: +0,
			dateFormat: "dd/mm/yy",
			defaultDate: new Date ( "January 1, 1992" )
		});
	}
	if($(".arrdate").length > 0) {
		$(".arrdate").datepicker({
			mandatory: true,
			dateFormat: "dd/mm/yy",
			defaultDate: new Date(2010, 08, 01),
			minDate: new Date(2010, 08, 01)
						
		});
	}
	if($(".depdate").length > 0) {
		$(".depdate").datepicker({
			mandatory: true,
			dateFormat: "dd/mm/yy",
			defaultDate: new Date(2011, 04, 31),
			minDate: new Date(2011, 04, 27)
			
		});
	}
	function CheckEmail(a){var b=/(.*)@(.*){3,}\.(.*)/i;return b.test(a)}
});


