$(function() {

	//Bind the change event for the Number of Passengers listbox
	var childIndex = 0;
	var changeNumberOfPassengers = function() {
		var index = $(this).val();
		iNumberOfTravellers = index;
		var oldIndex = $(".passengerTabs .on").get(0).className.replace(" on", "").replace("passenger", "");
		$(".passengerTabs a").each(function(i) {
			if (i < index) {
				$(this).show();
			} else {
				$(this).hide();
			}
		});
		if (oldIndex > index) $(".passengerTabs .passenger1").trigger("click");
		
		if (index > 0)
		{
			var childIndex = $("#lstNumChildren").val();
			$("#step1Children").show();
			$("#lstNumChildren option").remove();
			$("<option/>").text("Please Select").attr("value", "").appendTo("#lstNumChildren");
			for (i = 1; i < index; i++) 
			{
				$("<option/>").text(i).attr("value", i).appendTo("#lstNumChildren");
			}
			$("#lstNumChildren").val(childIndex);
		}
		else
		{
			$("#step1Children").hide();
			$("#lstNumChildren option").remove();
		}
		
		
	};
	$("#lstNumPassengers").change(changeNumberOfPassengers);
	//Make sure the correct number of tabs are shown on page reload
	$("#lstNumPassengers").trigger("change");
	$("#lstNumChildren").trigger("change");
	
	//Bind the click events for the Passenger tabs
	var clickPassengerTab = function(e) {
		var index = this.className.replace(" on", "").replace("passenger", "");
		$(".passengerTabs a").each(function(i) {
			$(this).removeClass("on");
			$("#passenger" + (i + 1) + "Details").hide();
		});
		$(this).addClass("on");
		$("#passenger" + index + "Details").show();
		e.preventDefault();
	};
	$(".passengerTabs a").click(clickPassengerTab);
	
	//Bind the click events for the payment methods
	//Make sure the correct payment method is shown on page reload
	
	//Bind the hover functionality on the question mark boxes
	var questionMarks = $(".quickBookFormRow .infoDiv");
	questionMarks.hover(
		function() {
			var visibleInfoBox = $("#quickBookInfoBox");
			if (visibleInfoBox.length == 0) {
				visibleInfoBox = $("<div></div>");
				visibleInfoBox.attr("id", "quickBookInfoBox");
				$("body").append(visibleInfoBox);
			}
			var text = $(this).children("p");
			visibleInfoBox.empty();
			visibleInfoBox.html(text.html());
			var itemPos = $(this).parent().offset();
			visibleInfoBox.css("left", itemPos.left + "px");
			visibleInfoBox.css("top", (itemPos.top + 17) + "px");
			visibleInfoBox.show();
		},
		function() {
			$("#quickBookInfoBox").hide();
		}
	);
	
	//Show the booking form if javascript is enabled
	$("#noJavascript").hide();
	$("#bookingForm").show();
	
});
