function switchMainImage(new_image_src)
{
	$("#mainImage").attr('src', new_image_src).fadeIn();
}

book_form_touched = false;

$(document).ready(function() {

	$(".faq_answer").hide();
	$(".faq_question").css('cursor', 'pointer');
	$(".faq_question").click(function() { $(this).next().fadeIn(); });


	$('body').keypress(function(e)
	{
	  if(e.which == 13 && book_form_touched)
	  {
	   $('#bookForm').submit();
		 e.preventDefault();
	  }
	});

	$("img[src$=booknow.png]").click(function()
	{
		$("#bookForm").submit();
	});
	
	function parseDate(str) 
	{
	   var mdy = str.split('/')
    return new Date(mdy[2], mdy[1]-1, mdy[0]);
	}


	function daydiff(first, second) 
	{
	    return (second-first)/(1000*60*60*24)
	}
	
	$("#checkIn").datepicker();
	$("#checkIn").datepicker('option', { dateFormat: 'dd/mm/yy' });
	$("#checkIn")[0].value = $.datepicker.formatDate("dd/mm/yy", new Date());

	$("#checkOut").datepicker();
	$("#checkOut").datepicker('option', { dateFormat: 'dd/mm/yy' });
	$("#checkOut")[0].value = $.datepicker.formatDate("dd/mm/yy", new Date());
	
 $("#ui-datepicker-div").addClass("invisible");
	$("#checkIn").change(function() {
		book_form_touched = true;
		var tomorrow = parseDate($("#checkIn")[0].value);
		tomorrow.setTime(tomorrow.getTime() + (1000*3600*24));
		var month = tomorrow.getMonth() + 1 + "";
		var date = tomorrow.getDate() + "";
		
		if (month.length == 1)
			month = "0" + month;
	
		if (date.length == 1)
			date = "0" + date;
		
		$("#checkOut")[0].value = date + "/" + month + "/" + tomorrow.getFullYear();
	});
	
	$("#checkOut").change(function() {
		book_form_touched = true;	
	});
	
	$(".bookButton").bind('click', function(e) {
		$("#bookForm").submit();
		e.preventDefault();		
	});
	
	$("#bookForm").bind('submit', function() {
		var checkInDate = $("#checkIn")[0].value.split("/");
		$("#checkInYear")[0].value = checkInDate[2];
		$("#checkInMonth")[0].value = checkInDate[1];
		$("#checkInDate")[0].value = checkInDate[0];			
		$("#numberOfNights")[0].value = daydiff(parseDate($("#checkIn")[0].value), parseDate($("#checkOut")[0].value));
		_gaq.push(['_trackEvent', 'book_now_link', 'clicked']);
		
	});

	var output = [];
	
	for(var i=0;i<30;i++)
	{
		output.push('<option value="'+ i +'">'+ i +'</option>');
	}
	
	$('#numberOfNights').get(0).innerHTML = output.join('');
	
	function googleDirectionsPopup(postal_code)
	{
		window.open('http://maps.google.com/maps?daddr=Mid+Stay+Car+Park,+Thremhall+Avenue,+London+Stansted+Airport,+Stansted,+CM24+1PZ,+United+Kingdom+(Holiday+Inn+Express+Stansted)&geocode=CWgy6s_PrUuMFS2VFwMdrdgDACHkIgIUXOg0SQ&dirflg=&saddr=' + postal_code + '&f=d&dq=express&spn=8.219195,17.072754');		
	}
	
	$("#getDirectionsLink").bind('click', function(e) {
		window.location = "/directions-to-stansted-airport/route-planner?postal_code=" + $('#postal_code')[0].value;
		
	});

	$("#postal_code").click(function() {
		if ($(this)[0].value == 'Enter Postal Code')
		{
			$(this)[0].value = '';
		}
	});

});


