﻿$(function() {
	var setDates = function () {
		today = new Date();
		with (today) setDate(getDate()+21);
		depDay  = today.getDate();
		depMon = today.getMonth() + 1;
		var tomorrow = new Date();
		with (tomorrow) setDate(getDate()+28)
		retDay = tomorrow.getDate();
		retMon = tomorrow.getMonth() + 1;
		$('select#depMonth option:eq('+ (depMon-1) +')').attr('selected', 'true');
		$('select#depDay option:eq('+ (depDay-1) +')').attr('selected', 'true');
		$('select#retMonth option:eq('+ (retMon-1) +')').attr('selected', 'true');
		$('select#retDay option:eq('+ (retDay-1) +')').attr('selected', 'true');
	}
	setDates();

	var toggleOneWay = function() {
		var state = $('#oneway').attr('checked') || false;

		$('#flight_type input:radio').each(function() {
		  $(this).next().removeClass('selected');
		}).filter(':checked').next().addClass('selected');

		$('#roundtrip_box input, #roundtrip_box select').attr('disabled', state);
		$('#roundtrip_box a.calendar_icon')[state ? 'addClass' : 'removeClass']('calendar_disabled');
	}
	toggleOneWay();
	$('#flight_type input:radio').click(toggleOneWay);

	$('#searchbox a').focus(function() { return this.blur(); });
	$('#flight_type input:radio').focus(function() { return this.blur(); });

	$('#searchbox input:text').focus(function(){
			$(this).addClass('focused');
		});
	$('#searchbox input:text').blur(function(){
			$(this).removeClass('focused');
	});

	$('#searchbox .hover_fix').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
});
