$(function()
{
	setSunday(1);
	setGuests(2);
	getCurrency();
	resetAdvancedSearch(0);
	showKidsAge();

	$("#city_menu ul li").mouseover(function() {
		$(this).addClass("over");
		$("span", this).addClass("over");
		$("span a", this).addClass("over");
	});
	$("#city_menu ul li").mouseout(function() {
		$(this).removeClass("over");
		$("span", this).removeClass("over");
		$("span a", this).removeClass("over");
	});

	$(".button").mouseover(function(){
		$(this).addClass("over");
	});
	$(".button").mouseout(function(){
		$(this).removeClass("over");
	});
	
	$(".date_pick").mouseover(function(){
		$("img", this).attr("src", "img/icon_calendar_on.gif");
	}).mouseout(function(){
		$("img", this).attr("src", "img/icon_calendar.gif");
	});
	$("#arrive_pick").click(function(){
		openCalendar("http://www.hotel-direct.ca/calendarStart.htm");
		return false;
	});
	$("#depart_pick").click(function(){
		openCalendar("http://www.hotel-direct.ca/calendarEnd.htm");
		return false;
	});
	$(".link").mouseover(function(){
		$("p a", this).attr("style", "color:#32C428");
	});

	$(".link").mouseout(function(){
		$("p a", this).attr("style", "");
	});
	
	$(".link").click(function(){
		location.href = $("a", this).attr("href");
		return false;
	});
	
	$(".hotel").mouseover(function(){
		$("p, a", this).attr("style", "color:#000000");
	});
	$(".hotel").mouseout(function(){
		$("p, a", this).attr("style", "");
	});
	
	$(".hotel").click(function(){
		location.href = $("a", this).attr("href");
		return false;
	});

	$("#rooms").change(function(){
		for (i = 2; i <= 5; i++)
		{
			$("#room_" + i).hide();
		}
		for (i = 2; i <= $(this).val(); i++)
		{
			$("#room_" + i).show();
		}
	});
	
	$(".room").change(function(){
		kids = 0;
		for (i = 1; i <= 5; i++)
		{
			if ($("#roomtype" + i).val().indexOf('family') > -1)
			{
				$("#kidsage_row").show();
				kids = 1;
			}
		}
		if (kids == 0)
			$("#kidsage_row").hide();
	});
	
	$("#nights").change(function(){
		setEndDate($(this).val());
	});
	
	$("#arrivedate, #arrivedate2").change(function(){
		setEndDate($("#nights").val());
	});
	
	$("#departdate, #departdate2").change(function(){
		setNights();
	});
	
	$(".advanced_2").change(function(){
		sel = $(this).attr("selectedIndex");
		$(".advanced_2").attr("selectedIndex", 0);
		$("#postcode").val("Postcode");
		$(this).attr("selectedIndex", sel);
	});
	
	$("#show_search").click(function(){
		$('#advanced_search').toggle();
		return false;
	});
	
	$("#postcode").click(function(){
		if ($(this).val() == "Postcode")
			$(this).val("");
	});
	$("#postcode").blur(function(){
		if ($(this).val() == "")
			$(this).val("Postcode");
		else
			$(".advanced_2").attr("selectedIndex", 0);
	});
	
	$(".closest_advanced").change(function(){
		sel = $(this).attr("selectedIndex");
		$(".closest_advanced").attr("selectedIndex", 0);
		$("#closest_postcode").val("Postcode");
		$("#closest_street").val("Street name");
		$(this).attr("selectedIndex", sel);
	});
	
	$("#closest_postcode").click(function(){
		if ($(this).val() == "Postcode")
			$(this).val("");
	});
	$("#closest_postcode").blur(function(){
		if ($(this).val() == "")
			$(this).val("Postcode");
		else
		{
			$(".closest_advanced").attr("selectedIndex", 0);
			$("#closest_street").val("Street name");
		}
	});
	
	$("#closest_street").click(function(){
		if ($(this).val() == "Street name")
			$(this).val("");
	});
	$("#closest_street").blur(function(){
		if ($(this).val() == "")
			$(this).val("Street name");
		else
		{
			$(".closest_advanced").attr("selectedIndex", 0);
			$("#closest_postcode").val("Postcode");
		}
	});
	
	$("a.select").click(function(){
		if ($(this).prev().val() != "")
			location.href = $(this).prev().val();
		return false;
	}).mouseover(function(){
		$("img", this).attr("src", "img/search_arrow_on.gif");
	}).mouseout(function(){
		$("img", this).attr("src", "img/search_arrow.gif");
	});
	
	$("a.postcode").click(function(){
		if (($("#closest_postcode").val() != "") && ($("#closest_postcode").val() != "Postcode"))
			location.href = $("#closest_postcode_url").val() + $("#closest_postcode").val();
		return false;
	}).mouseover(function(){
		$("img", this).attr("src", "img/search_arrow_on.gif");
	}).mouseout(function(){
		$("img", this).attr("src", "img/search_arrow.gif");
	});
	
	$("a.street").click(function(){
		if (($("#closest_street").val() != "") && ($("#closest_street").val() != "Street name"))
			location.href = $("#closest_street_url").val() + $("#closest_street").val();
		return false;
	}).mouseover(function(){
		$("img", this).attr("src", "img/search_arrow_on.gif");
	}).mouseout(function(){
		$("img", this).attr("src", "img/search_arrow.gif");
	});
	
	$("#home_form").submit(function(){
		return checkHomeSearch();
	});
	
	$("#city_map area").mouseover(function(){
		$("#city_map_img").attr("src", "img/" + $(this).attr("name").toLowerCase() + "_city_map_" + $(this).attr("id") + ".gif");
	}).mouseout(function(){
		$("#city_map_img").attr("src", "img/city_map_" + $(this).attr("name").toLowerCase() + ".gif");
	});
});
