$(document).ready(function() {
/* Utility */
	function cl(to_console){
		console.log(to_console);	
	}
	
	$("a.preventDefault").click(function(e){
		e.preventDefault();
	});
	
	$(".remove_none").removeClass("none");
	$(".remove_none").removeClass("remove_none");
	$(".fadeOut").fadeOut();
	
	$('.date-picker').datepicker({
		dateFormat: 'dd/mm/yy',
		minDate: +0,
		onClose: function() {
										  
		  window.date_of_trip_date_set = true;		
		  
			if(window.lodge && window.arrival_date_set && window.departure_date_set && window.date_of_trip_date_set && window.nights_stay > 0){
				is_inbetween($('#arrival_date_accomodation').val(), $('#departure_date_accomodation').val(), $('#date_of_trip').val());
			}	  				
			
		}		
	});	

/* End Utility */

/* On page load */

	Cufon.replace('.bebas', { fontFamily: 'bebas' });
  	Cufon.replace('h2');
	
	$('select.styled').customStyle();

	$(".extra_fancy_box_info").hide();
	
    $(window).load(function() {
        $('#slider, #slider_full_package').nivoSlider({
        	effect: 'fade',
			directionNavHide: true,
			controlNav: false,
			startSlide: 0,
			pauseTime: 6000
		});
    });
	
	//Check if there are any (a.click_me_now) links to click
	$("a").each(function(){
		if($(this).hasClass("click_me_now")){
			$(this).fancybox({
				padding:0,
				overlayOpacity:.9,
				scrolling: 'no',
				overlayColor:'#333',
				speedIn: 600,
				onComplete: function(){
					/*
					|$(this) is the clicked link so gets its href eg div id to load
					|then find its price div and prepend it to the fancybox top shadow
					|so that it can be positioned absolutely to it
					*/
					window.get_price_from_div_id = "";
					window.get_price_from_div_id = $(this).attr('href');
					$(window.get_price_from_div_id).children(".extra_fancy_box_info").prependTo('#fancybox-outer');
					$("#fancybox-outer .extra_fancy_box_info").fadeIn();
				},
				onClosed: function(){
					/*
					|Now we need to clean up and put the price back in its overlay div so
					|that we can put a different price etc in its place late
					*/
					$('#fancybox-outer').children(".extra_fancy_box_info").hide();
					$('#fancybox-outer').children(".extra_fancy_box_info").prependTo(window.get_price_from_div_id);
				}
			}).trigger("click");
		}
	})
	
	$("input").focus(function(){
		if($(this).val() == "Name" || $(this).val() == "Email" || $(this).val() == "Phone" || $(this).val() == "Address" || $(this).val() == "0"){
			$(this).val("");
		}
	});
	
	$("input").blur(function(){
		if($(this).hasClass("show_name") && $(this).val() == ""){
			$(this).val("Name");
		}else if($(this).hasClass("show_email") && $(this).val() == ""){
			$(this).val("Email");
		}else if($(this).hasClass("show_phone") && $(this).val() == ""){
			$(this).val("Phone");
		}else if($(this).hasClass("show_address") && $(this).val() == ""){
			$(this).val("Address");
		}else if($(this).hasClass("show_zero") && $(this).val() == ""){
			$(this).val("0");
		}else if($(this).hasClass("show_date_click") && $(this).val() == ""){
			$(this).val("Click to chose date");
		}
	});
	
	$(".show_me_if_js table.itinerary tr.count_me:even").addClass("alt_row");
	$(".show_me_if_js table.totals tr.count_me:even").addClass("alt_row");
	
	$(".show_me_if_js").removeClass("none");
	$(".hide_if_js").addClass("none");
	
	//Only do sidebar scrolling on the booking page
	if($(".sidebar_extras").hasClass("booking")){
		
		$("#scrollbars").scrollTop(0);
				
		//Slide the sidebar down the page (Bookings page)
		var offset = $("#move_me").offset();
		var topPadding = 65;

		$("#scrollbars").scroll(function() {
			if ($("#scrollbars").scrollTop() > offset.top) {
				$("#move_me").stop().animate({
					marginTop: $("#scrollbars").scrollTop() - offset.top + topPadding
				});
			} else {
				$("#move_me").stop().animate({
					marginTop: 0
				});
			}		
		});			
	}
	
	$("a.fancyBox").fancybox({
		padding:0,
		overlayOpacity:.9,
		scrolling: 'no',
		overlayColor:'#333',
		onComplete: function(){
			/*
			|$(this) is the clicked link so gets its href eg div id to load
			|then find its price div and prepend it to the fancybox top shadow
			|so that it can be positioned absolutely to it
			*/
			window.get_price_from_div_id = "";
			window.get_price_from_div_id = $(this).attr('href');
			$(window.get_price_from_div_id).children(".extra_fancy_box_info").prependTo('#fancybox-outer');
			$("#fancybox-outer .extra_fancy_box_info").fadeIn();
		},
		onClosed: function(){
			/*
			|Now we need to clean up and put the price back in its overlay div so
			|that we can put a different price etc in its place late
			*/
			$('#fancybox-outer').children(".extra_fancy_box_info").hide();
			$('#fancybox-outer').children(".extra_fancy_box_info").prependTo(window.get_price_from_div_id);
		}
	});
	
/* End On page load */

/* Email address validation function */
function verifyEmail(email_field){
var status = false;     
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (email_field.search(emailRegEx) == -1) {
		  return false;
	 }else{
		  return true; 
	 }
}

/* Price tag wiggle */

$("#full_package_content, #price_tag").hover(function(){
	
	var slide_in_out_time = 180;
	
	if(!$("#price_tag").hasClass("already_wiggled")){
		$("#price_tag").animate({
			right:-59
		}, slide_in_out_time, function(){
			$("#price_tag").animate({
				right:-65
			}, slide_in_out_time);	
		});
	}
	
	$("#price_tag").addClass("already_wiggled")
	
});

/* End Price tag wiggle */

/* Booking Page */
	
	/* Table alt row counter */
	window.alt_row = true;
	window.packageCost = $("#package_cost").val();
	window.package_discount = parseFloat("." + $("#package_discount").val());
	window.transfer_costs = 0;
	
	window.tickets = 0;
	window.transfers = 0;
	window.accom = 0;
	window.lunches = 0;
	window.nights_stay = 0;

	//Allow only number in .numbers_only text fields
	$(".numbers_only").keydown(function(event) {
		// Allow only backspace and delete
		if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 ) {
			// let it happen, don't do anything
		}
		else {
		// Ensure that it is a number and stop the keypress
			if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
				event.preventDefault(); 
			}   
		}
	});
	
	//Add comma's eg 9,999	
	function addCommas(nStr)
	{
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	
	//Update ticket price
	function ticket_price(){
		var new_tickets_cost = $("#quantity").val() * window.packageCost;
		window.tickets_pax = $("#quantity").val();
		
		$(".overall_total.tickets").fadeOut(function(){
			$(this).text(addCommas(parseFloat(new_tickets_cost).toFixed(2)));
			$(this).fadeIn();
		});
		
		window.tickets = parseFloat(new_tickets_cost).toFixed(2);
		
		return parseFloat(new_tickets_cost);
	}
	
	//Update transfer cost
	function transfers_price(current_select){
		//Add a class to hook onto the current select
		current_select.addClass("current_list");
		
		//Set the default vars
		var transfer_cost = $(".current_list option:selected").attr("class");
		var transfer_pax = current_select.parent(".segment_block_wrapper").children(".airport_pax").val();
		var transfer_total = transfer_cost * transfer_pax;			
		var all_transfer_totals = 0;
		var all_transfer_totals = 0;
		
		//Set the value of the hidden input that tracks this transfers total
		current_select.parent(".segment_block_wrapper").children(".transfer_costs_sub_total").val(transfer_total);	
	
		//Add up all of the hidden trans fer totals
		$(".transfer_costs_sub_total").each(function(){
			all_transfer_totals = parseFloat(all_transfer_totals) + parseFloat($(this).val());
		});
				
		//Fade out, update and fade in sidebar subtotals		
		$(".overall_total.transfers").fadeOut(function(){
			$(this).text(addCommas(all_transfer_totals));
			$(this).fadeIn();
		});
		
		
		//Remove the select hook
		current_select.removeClass("current_list");
		
		window.transfers = parseFloat(all_transfer_totals);
		
		//Return all transfer totals
		return parseFloat(all_transfer_totals);
	}
	
	//Update extra accom costs
	function accomodation(){
		

		var accomo_type = $(".accomodation_type_selection option:selected").attr("class");
		var accom_total = 0;
		var accom_total_to_show = 0;
		window.accomodationtype = "";	
		
		if(accomo_type == "motel"){
			if($("#quantity").val() == "0"){
				accom_total = addCommas(parseFloat(window.accom0).toFixed(2));
			}else if($("#quantity").val() == "1"){
				accom_total = addCommas(parseFloat(window.accom1).toFixed(2));				
			}else if($("#quantity").val() == "2"){
				accom_total = addCommas(parseFloat(window.accom2).toFixed(2));				
			}else if($("#quantity").val() == "3"){
				accom_total = addCommas(parseFloat(window.accom3).toFixed(2));				
			}else if($("#quantity").val() == "4"){
				accom_total = addCommas(parseFloat(window.accom4).toFixed(2));				
			}else if($("#quantity").val() == "5"){
				accom_total = addCommas(parseFloat(window.accom5).toFixed(2));				
			}else if($("#quantity").val() == "6"){
				accom_total = addCommas(parseFloat(window.accom6).toFixed(2));				
			}else if($("#quantity").val() == "7"){
				accom_total = addCommas(parseFloat(window.accom7).toFixed(2));				
			}
			
			window.accomodationtype = "Motel";
			
		}else if(accomo_type == "backpackers"){
			
			var accom_total_to_show = 0;
			
			$(".backpackers_room_select option:selected").each(function(){
				var backpacker_room_cost = parseFloat($(this).attr("class"));
				accom_total = parseFloat(accom_total) + parseFloat(backpacker_room_cost);
			});

			window.accomodationtype = "Backpackers";
			
		}else{
			var accom_total = 0.00;
			window.accomodationtype = "";
			
		}
		
		if(parseFloat(window.nights_stay) == 0){
			var accom_total_to_show = 0;
		}else{
			if(window.lodge_overlaps_accom){
				var accom_total_to_show = parseFloat(accom_total) * (parseFloat(window.nights_stay) - 1);
			}else{
				var accom_total_to_show = parseFloat(accom_total) * parseFloat(window.nights_stay);
			}			
		}		
		
		if($("#quantity").val() > 6 && window.accomodationtype != "Backpackers"){
			accom_total_to_show = 0;
			$(".accomodation_date_selection").addClass("none");
		}
		
		//Fade out, update and fade in sidebar subtotals		
		$(".overall_total.accomodation").fadeOut(function(){
			$(this).text(addCommas(parseFloat(accom_total_to_show).toFixed(2)));
			$(this).fadeIn();
		});		
		
		window.accom = parseFloat(accom_total_to_show);
		
		return parseFloat(accom_total);		
	}
	
	//Echo another backpackers room
	$("a#backpackers_room_block").click(function(){
		$(".backpackers_room_block:first").clone(true).appendTo("#show_all_backpackers_rooms");
		$(".backpackers_room_block .backpackers_room_select").last().val("0");
		accomodation();
		update_grand_total();
	});	
	
	//Update lunch total
	function lunch_total(lunch_amount){
		
		//Lunch quantity and price
		var lunch_pax = lunch_amount.val();
		var lunch_cost = $(".lunch_cost").val();		
		var lunch_total = parseFloat(lunch_pax) * parseFloat(lunch_cost);
		var lunch_total = lunch_total.toFixed(0);
		
		//Fade out, update and fade in sidebar subtotals		
		$(".overall_total.lunches").fadeOut(function(){
			$(this).text(addCommas(lunch_total));
			$(this).fadeIn();
		});	
		
		window.lunches = parseFloat(lunch_total);
		
		return lunch_total;		
	}

	//Get time stamps for comparison
	function getTimestamp(dateonly){
		var dateonly_to_string = String(dateonly);
		var dmy = dateonly_to_string.split('/');

		var year = dmy[2];
		var month = parseFloat(dmy[1]) - 1;
		var day = dmy[0];
			
		var datum = new Date(Date.UTC(year, month, day,'0','01','0'));
		timestamp = datum.getTime()/1000;	
		
		return timestamp;
	}
		
	//Update grand total
	function update_grand_total(){
		
		var grand_total = parseFloat(window.tickets) + parseFloat(window.transfers) + parseFloat(window.accom) + parseFloat(window.lunches);
		
		if(window.tickets_pax >= 4){
			
			//If .none then remove it
			if($("tr.discount_row").hasClass("none")){
				$("tr.discount_row").removeClass("none");
			}
			
			//Remove class
			if($("tr.grand_total_minus_discount").hasClass("none")){
				$("tr.grand_total_minus_discount").removeClass("none");
			}
			
			//Work out the total discount
			$(".overall_total.discount").fadeOut(function(){
				window.discount_amount = parseFloat(grand_total * window.package_discount);
				var discount_amount_string = parseFloat(window.discount_amount);
				var discount_string_shortened = discount_amount_string.toFixed(0);
				$(".overall_total.discount").text(addCommas(discount_string_shortened));
				$(".overall_total.discount").fadeIn();
			});
			
			//Relay this info to he user
			$(".overall_total.grand_total_minus_discount").fadeOut(function(){
				var grand_total_minus_discount = parseFloat(grand_total - window.discount_amount).toFixed(0);
				$(".overall_total.grand_total_minus_discount").text(addCommas(parseFloat(grand_total_minus_discount).toFixed(2)));
				$(".overall_total.grand_total_minus_discount").fadeIn();
			});
			 	
		}else{
			
			//If no .none then add it
			if(!$("tr.discount_row").hasClass("none")){
				$("tr.discount_row").addClass("none");
			}
			
			//Add class
			if(!$("tr.grand_total_minus_discount").hasClass("none")){
				$("tr.grand_total_minus_discount").addClass("none");
			}
			
		}
		
		//Fade out, update and fade in sidebar subtotals		
		$(".overall_total.grand_total").fadeOut(function(){
				$(this).text(addCommas(parseFloat(grand_total).toFixed(2)));
				$(this).fadeIn();
		});			
		
		return grand_total;
	}
	
	$(".backpackers_room_select").change(function(){
		accomodation();
		update_grand_total();	
	});
	
	//Duplicate airport transfers block
	$("a#airport_transfer_block").click(function(){
		$(".airport_transfers_wrapper .airport_transfer_block:first").clone(true).appendTo(".airport_transfers_wrapper");
		$(".airport_transfers_wrapper .airport_pax").last().val("0");
		$(".airport_transfers_wrapper .transfer_costs_sub_total").last().val("0");
	});

	$(".airport_transfer").change(function() {
		transfers_price($(this));
	});	
	
	$(".airport_pax").change(function() {
		transfers_price($(this).parent(".segment_block_wrapper").children(".airport_transfer"));
	});		
		
	$("#quantity").blur(function(){

		accomodation();
		
		ticket_price();
		
		update_grand_total();
				
		if($("#quantity").val() < 7 && $("#quantity").val() > 0 && window.accomodationtype == "Motel"){
			$(".accomodation_date_selection").removeClass("none");
		}
		
		//Set people or person
		if($("#quantity").val() == 1){
			$(".people_or_person").text(" person");
		}else{
			$(".people_or_person").text(" people");
		}
		
		//Fade on errors if quantity is zero or blank
	  	if($("#quantity").val() != 0 && $("#quantity").val() != ""){
			$("#quantity").removeClass("error");
			$(".quantity_error").fadeOut();
		}
				
		//Hide all motel options
		$("p.motel_room_option").addClass("none");
		if(!$("span#greater_than_7").hasClass("none")){
			$("span#greater_than_7").addClass("none");
		}

		//If quantity is 0 or nothing then show information asking user to enter quantity
		if(($("#quantity").val() == "0" || $("#quantity").val() == "")){
			if($("span.motel_room_option").hasClass("none")){
				$("span.motel_room_option").removeClass("none");
				$("span#greater_than_7").addClass("none");
			}
		}else{
			$("span.motel_room_option").addClass("none");
		}
		
		//If quantity is greater than 6 then show p#greater_than_7
		if($("#quantity").val() > 6){
			$("span#greater_than_7").removeClass("none");
		}else{
			//Show the corresponding motel option for how many people are booking
			if($("#quantity").val() >= 0){
				$("p#" + $("#quantity").val() + "").removeClass("none");
			}
		}
		
		$("#motel_pax").text($("#quantity").val());
	});
	
	$(".accomodation_type_selection").change(function() {
		$(this).addClass("processing_list");
		var accomodation_type = $(".processing_list option:selected").attr("class");
		$(".motel_selection").addClass("none");
		$(".backpackers_selection").addClass("none");
		$("." + accomodation_type + "_selection").removeClass("none");
		$(".processing_list").removeClass("processing_list");
		
		if(accomodation_type != "accomodation_null"){
			$(".accomodation_date_selection").removeClass("none");
		}else{
			$(".accomodation_date_selection").addClass("none");			
		}
		
		accomodation();
		
		update_grand_total();
	});		
	
	$("#cooked_lunch").blur(function(){
		lunch_total($(this));
	});
	
	$("#date_of_trip").blur(function(){
		if($("#date_of_trip").val() != "" || $("#date_of_trip").val() != "Click to chose date"){
			$("#date_of_trip").removeClass("error");
			$(".date_of_trip_error").fadeOut();
		}		
	});
	
	$("#name").blur(function(){
		if($("#name").val() != "" && $("#name").val() != "Name"){
			$("#name").removeClass("error");
			$(".name_error").fadeOut();
		}	
	});	
	
	$("#phone").blur(function(){		
		if($("#phone").val() != "" && $("#phone").val() != "Phone"){
			$("#phone").removeClass("error");
			$(".phone_error").fadeOut();
		}	
	});	
	
	$("#email").blur(function(){
		if($("#email").val() != "" && $("#email").val() != "Email"){

			$(".email_error").fadeOut();
			
			  if(verifyEmail($("#email").val())){
				$("#email").removeClass("error");
				$(".email_address_not_valid").fadeOut(); 			
			  }			
		}	
	});			
	
	$("input").blur(function(){
		if(!$(this).hasClass("show_name") || !$(this).hasClass("show_email") || !$(this).hasClass("show_phone") || !$(this).hasClass("show_date_click")){
			update_grand_total();
		}	
	});
	
	/* Form validation */
	
	$('#booking_form').submit(function(e) {
		
	  if(!verifyEmail($("#email").val())){
		$("#email").addClass("error");
		$(".email_address_not_valid").fadeIn(); 			
	  }
		
	  if($("#quantity").val() == 0 || $("#quantity").val() == ""){
		$("#quantity").addClass("error");
		
		$(".quantity_error").fadeIn(); 
	  }
	  
	  if($("#message").val() == ""){
		$("#message").addClass("error");
		$(".message_error").fadeIn(); 
	  }	  	  
	  
	  if($("#date_of_trip").val() == "" || $("#date_of_trip").val() == "Click to chose date"){
		$("#date_of_trip").addClass("error");		
		$(".date_of_trip_error").fadeIn();
	  }
	  
	  if($("#name").val() == "" || $("#name").val() == "Name"){
		$("#name").addClass("error");		
		$(".name_error").fadeIn();
	  }
	  
	  if($("#phone").val() == "" || $("#phone").val() == "Phone"){
		$("#phone").addClass("error");		
		$(".phone_error").fadeIn();
	  }
	  
	  if($("#email").val() == "" || $("#email").val() == "Email"){
		$("#email").addClass("error");		
		$(".email_error").fadeIn();
	  }	 

	  if(window.accomodationtype == "Motel" || window.accomodationtype == "Backpackers"){
		  if($("#departure_date_accomodation").val() == "Click to chose date"
		   || $("#departure_date_accomodation").val() == ""
		    || $("#arrival_date_accomodation").val() == "Click to chose date"
			 || $("#arrival_date_accomodation").val() == ""){
			  $(".accomodation_dates_error").fadeIn();
		  }
	  }	  
 
 	  $("input").each(function(){
		  if($(this).hasClass("error")){
	  		 e.preventDefault();
			 return false;		  
		  }
	  });	
	  
	});
	
	$("#enquiry_form #name:last").blur(function(){
	  if($(this).val() != "Name" && $(this).val() != ""){
		$(".name_error_enquiry").fadeOut(); 
		$(this).removeClass("error");
	  }
	});
	
	$(".email_or_phone").blur(function(){
	  if(($("#enquiry_form #email_for_enquiry").last().val() != "Email" && $("#enquiry_form #email_for_enquiry").last().val() != "") || ($("#enquiry_form #phone_for_enquiry").last().val() != "Phone" && $("#enquiry_form #phone_for_enquiry").last().val() != "")){
		$(".email_or_phone_enquiry_error").fadeOut();
		$("#enquiry_form .email_or_phone").removeClass("error");		
	  }	 
	});	
	
	$("#message_for_enquiry").blur(function(){
	  if($(this).val() != ""){
		$(".message_for_enquiry_error").fadeOut();
		$(this).removeClass("error");
	  }		
	});
	
	$('#enquiry_form:last').submit(function(e) {
		
	  window.enquiry_form_errors = false;
		
	  if($("#enquiry_form #name").last().val() == "Name" || $("#enquiry_form #name").last().val() == ""){
		$(".name_error_enquiry").fadeIn(); 
		$("#enquiry_form #name").last().addClass("error");
		window.enquiry_form_errors = true;
	  }
	  
	  if($("#enquiry_form #message_for_enquiry").last().val() == ""){
		$(".message_for_enquiry_error").fadeIn();
		$("#enquiry_form #message_for_enquiry").last().addClass("error");		
		window.enquiry_form_errors = true;
	  }
	  
	  if(($("#enquiry_form #email_for_enquiry").last().val() == "Email" || $("#enquiry_form #email_for_enquiry").last().val() == "") && ($("#enquiry_form #phone_for_enquiry").last().val() == "Phone" || $("#enquiry_form #phone_for_enquiry").last().val() == "")){
		$(".email_or_phone_enquiry_error").fadeIn();
		$("#enquiry_form .email_or_phone").addClass("error");		
		window.enquiry_form_errors = true;
	  }	  

 	  if(window.enquiry_form_errors){
	  		 e.preventDefault();
			 return false;		  
	  }
	  
	});	

	/* End Form Validation */	
	
	/* Contact form validation */
	
	$("#email_for_contact, #phone_for_contact").blur(function(){
		if(($("#email_for_contact").val() != "" && $("#email_for_contact").val() != "Email") || ($("#phone_for_contact").val() != "" && $("#phone_for_contact").val() != "Phone")){
			 $(".email_or_phone_error").fadeOut();
			 $("#email_for_contact").removeClass("error");
			 $("#phone_for_contact").removeClass("error");			 
		}		
	});
	
	$("#message_for_contact").blur(function(){
		//Fade out error if contact page message isnt blank
	  	if($("#message_for_contact").val() != ""){
			$("#message_for_contact").removeClass("error");
			$(".message_for_contact_error").fadeOut();
		}	
	});
	
	$('#contact_form').submit(function(e) {

		if(($("#email_for_contact").val() == "" || $("#email_for_contact").val() == "Email") && ($("#phone_for_contact").val() == "" || $("#phone_for_contact").val() == "Phone")){
			 $(".email_or_phone_error").fadeIn();
			 $("#email_for_contact").addClass("error");
			 $("#phone_for_contact").addClass("error");			 
		}
		
	  if($("#name").val() == "" || $("#name").val() == "Name"){
		$("#name").addClass("error");		
		$(".name_error").fadeIn();
	  }		
		
		//Fade in error if contact page message is blank
	  	if($("#message_for_contact").val() == ""){
			$("#message_for_contact").addClass("error");
			$(".message_for_contact_error").fadeIn();
		}
				
		$("#contact_form input").each(function(){
		  if($(this).hasClass("error")){
	  		 e.preventDefault();
			 return false;		  
		  }
	  });			
	});
		
/* End Booking Page */

/* Booking processing page */

if($("#small_info_wrapper").hasClass("processing")){
	$("#small_info_wrapper").delay(2000).fadeOut(function(){
		$("#small_info_wrapper.processing span.big_info_line").text("Now redirecting you...");	
		$("#small_info_wrapper.processing span.small_info_line").text("We will be in touch to confirm with " + window.hours_to_confirm + " hours");			
	}).delay(400).fadeIn(function(){
		$("#processing_information_box img.loader").delay(2000).fadeOut(function(){
			window.location = "http://adventurefiordland.co.nz/";
		});
	});
	
/* Contact processing page */
}else if($("#small_info_wrapper").hasClass("processing_contact")){
	$("#small_info_wrapper").delay(2000).fadeOut(function(){
		$("#small_info_wrapper.processing_contact span.big_info_line").text("Now redirecting you...");	
		$("#small_info_wrapper.processing_contact span.small_info_line").text("Your enquiry has been sent");			
	}).delay(400).fadeIn(function(){
		$("#processing_information_box img.loader").delay(2000).fadeOut(function(){
			window.location = "http://adventurefiordland.co.nz/";
		});
	});
}

/* Booking Dates */

/* Date picker initialisation and onSelects */

				function parseDate(str) {

					var mdy = str.split('/');

					return new Date(mdy[2], mdy[1]-1, mdy[0]-1);

				}

				function daydiff(first, second) {

					return Math.floor((second-first)/(1000*60*60*24)+1);

				}
				
				function is_inbetween(date_start, date_finish, date_inbetween){
					
					window.lodge_overlaps_accom = false;
					
					$("p#dates_overlap").text("");
					$("#dates_overlap_hidden").val("0");
					
					var date_start_time_stamp = getTimestamp(date_start);
					var date_finish_time_stamp = getTimestamp(date_finish);
					var date_inbetween_time_stamp = getTimestamp(date_inbetween);
					
					if(date_inbetween_time_stamp < date_finish_time_stamp && date_inbetween_time_stamp > date_start_time_stamp){						
						$("p#dates_overlap").text("Your accomodation dates overlap your stay at the lodge so we have taken of the price of a nights stay and we will hold your bags for FREE while you are away");
						$("#dates_overlap_hidden").val("1");
						window.lodge_overlaps_accom = true;
					}
					
					accomodation();
					
					return true;
				}

				$('#arrival_date_accomodation').datepicker({

					dateFormat: 'dd/mm/yy',
					minDate: +0,
					onClose: function() {														
												
							accomodation();
							update_grand_total();
						
							//Remove form submit error if its added	
						  if(window.accomodationtype == "Motel" || window.accomodationtype == "Backpackers"){
							  if($("#departure_date_accomodation").val() != "Click to chose date" || $("#departure_date_accomodation").val() != ""
								&& $("#arrival_date_accomodation").val() != "Click to chose date" || $("#arrival_date_accomodation").val() != ""){
								  $(".accomodation_dates_error").fadeOut();
							  }
						  }							
						
						window.arrival_date_set = true;	
														
						if(window.lodge && window.arrival_date_set && window.departure_date_set && window.date_of_trip_date_set && window.nights_stay > 0){
							is_inbetween($('#arrival_date_accomodation').val(), $('#departure_date_accomodation').val(), $('#date_of_trip').val());
						}
							
						},					
					onSelect: function(dateText, inst){

						$('#departure_date_accomodation').datepicker('option', 'minDate', $('#arrival_date_accomodation').datepicker("getDate"));
						
						var startString = $('#arrival_date_accomodation').val();
						var finishString = $('#departure_date_accomodation').val();
						
						if(finishString != ''){

							var nights_stay = daydiff(parseDate(startString), parseDate(finishString)) - 1;

							window.nights_stay = nights_stay;

						}

					}

				});

				

				$('#departure_date_accomodation').datepicker({

					dateFormat: 'dd/mm/yy',
					minDate: +0,
					onClose: function() {
												
							accomodation();
							update_grand_total();
						
							//Remove form submit error if its added	
						  if(window.accomodationtype == "Motel" || window.accomodationtype == "Backpackers"){
							  if($("#departure_date_accomodation").val() != "Click to chose date" || $("#departure_date_accomodation").val() != ""
								&& $("#arrival_date_accomodation").val() != "Click to chose date" || $("#arrival_date_accomodation").val() != ""){
								  $(".accomodation_dates_error").fadeOut();
							  }
						  }													  
						  
						  window.departure_date_set = true;						
							
						if(window.lodge && window.arrival_date_set && window.departure_date_set && window.date_of_trip_date_set && window.nights_stay > 0){
							is_inbetween($('#arrival_date_accomodation').val(), $('#departure_date_accomodation').val(), $('#date_of_trip').val());
						}
														
						},
					onSelect: function(dateText, inst){
						
						accomodation();
						
						$('#arrival_date_accomodation').datepicker("option", 'maxDate', $('#departure_date_accomodation').datepicker("getDate"));	

						var startString = $('#arrival_date_accomodation').val();
						window.arrival_accom = startString;
						var finishString = $('#departure_date_accomodation').val();
						window.departure_accom = finishString;
						
						if(startString != ''){

							var nights_stay = daydiff(parseDate(startString), parseDate(finishString)) - 1;

							window.nights_stay = nights_stay;

						}

					}

				});


/* End booking dates */

/* End Booking processing page */

/* Test Area - Del when live */
	
/* End Test Area - Del when live */

});
