state = 0;

$(function()
{
	setSunday(0);
	setGuests(1);
	window.name='HDBookPage';
	showKidsAge2();
	getCurrency();
	
	$(".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.hoteldirecteurope.com/calendarStart.htm");
		return false;
	});
	$("#depart_pick").click(function(){
		openCalendar("http://www.hoteldirecteurope.com/calendarEnd.htm");
		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();
		setGuests(1);
	});
	
	$("#kidsage").blur(function(){
		setGuests(1);
	});
	
	$("#nights").change(function(){
		setEndDate($(this).val());
	});
	
	$("#arrivedate, #arrivedate2").change(function(){
		setEndDate($("#nights").val());
	});
	
	$("#departdate, #departdate2").change(function(){
		setNights();
	});
	
	$("#city_menu ul li, #city_menu_distance ul li").mouseover(function() {
		$(this).addClass("over");
		$("span", this).addClass("over");
		$("span a", this).addClass("over");
	});
	$("#city_menu ul li, #city_menu_distance ul li").mouseout(function() {
		$(this).removeClass("over");
		$("span", this).removeClass("over");
		$("span a", this).removeClass("over");
	});
	
	$(".sort_up").mouseover(function() {
		if ($("img", this).attr("src") == "img/sort_up.gif")
		{
			$("img", this).attr("src", "img/sort_up_over.gif");
		}
	}).mouseout(function() {
		if ($("img", this).attr("src") == "img/sort_up_over.gif")
		{
			$("img", this).attr("src", "img/sort_up.gif");
		}
	});
	$(".sort_down").mouseover(function() {
		if ($("img", this).attr("src") == "img/sort_down.gif")
		{
			$("img", this).attr("src", "img/sort_down_over.gif");
		}
	}).mouseout(function() {
		if ($("img", this).attr("src") == "img/sort_down_over.gif")
		{
			$("img", this).attr("src", "img/sort_down.gif");
		}
	});
	
	/*$("a.select").click(function(){
		if ($(this).prev().val() != "")
		{
			val = $(this).prev().val();
			if (val.indexOf("|") > -1)
			{
				url = val.substring(0, val.indexOf("|"));
			}
			else
			{
				url = val;
			}
			location.href = url;
		}
		return false;
	}).mouseover(function(){
		$("img", this).attr("src", "img/search_arrow_green_on.gif");
	}).mouseout(function(){
		$("img", this).attr("src", "img/search_arrow_green.gif");
	});*/
	$("a.select").click(function(){
		$("#submit").click();
		return false;
	}).mouseover(function(){
		$("img", this).attr("src", "img/search_arrow_green_on.gif");
	}).mouseout(function(){
		$("img", this).attr("src", "img/search_arrow_green.gif");
	});
	
	$(".button").mouseover(function(){
		$(this).addClass("over");
	});
	$(".button").mouseout(function(){
		$(this).removeClass("over");
	});
	
	$("#city_map area").mouseover(function(){
		$("#city_map_img").attr("src", "img/" + $(this).attr("name").toLowerCase() + "_city_map_" + $(this).attr("id") + ".gif");
	}).mouseout(function(){
		if (area != "")
			$("#city_map_img").attr("src", "img/" + $(this).attr("name").toLowerCase() + "_city_map_" + area + ".gif");
		else
			$("#city_map_img").attr("src", "img/city_map_" + $(this).attr("name").toLowerCase() + ".gif");
	});
	
	$(".closest_advanced").change(function(){
		sel = $(this).attr("selectedIndex");
		$(".closest_advanced").attr("selectedIndex", 0);
		$(this).attr("selectedIndex", sel);
	});
	
	$("a.gem").mouseover(function(){
		cookie = document.cookie;
		broken_cookie = cookie.split(";");
		m = broken_cookie.length;
		found='';

		for (i=0; i<m; i++)
		{
			broken_cookie[i] = trimCookie(broken_cookie[i]);
			if (broken_cookie[i].indexOf('hiddengemhotel=')>-1) 
			{
				found='yes';
				break;
			}
	
		}
		if (found=='') 	
		{
			document.cookie = "hiddengemhotel=yes; domain=www.hoteldirecteurope.com; path=/;";
			//openWindow('http://www.hoteldirecteurope.com/hiddengems.htm', 330, 220, 'no');
		}
	});
	
/*	$(".order ul li a").mouseover(function() {
		if ($(this).hasClass("down"))
		{
			$(this).removeClass("down");
			$(this).addClass("up");
			state = 1;
		}
		else if ($(this).hasClass("up"))
		{
			$(this).removeClass("up");
			$(this).addClass("down");
			state = 2;
		}
		else
		{
			$(this).addClass("down");
			state = 0;
		}
	}).mouseout(function() {
		if (state == 1)
		{
			$(this).removeClass("up");
			$(this).addClass("down");
		}
		else if (state ==2)
		{
			$(this).removeClass("down");
			$(this).addClass("up");
		}
		else
		{
			$(this).removeClass("down");
		}
	});*/

	$('div.result').each(function(){
		var o = $(this).height();
		var i = 0;
		if ($('div.hotel_info', this).is('*'))
		{
			i = $('div.hotel_info', this).height();
		}
		if ($('div.price', this).is('*'))
		{
			var h = 0;
			$('div.price p', this).each(function(){
				h = h + $(this).height();
			});
			$('div.price').css({'overflow':'visible'});
			if (i > (h + 19))
			{
				h = i;
			}
			else
			{
				h = h + 19;
			}
			if (h > 47)
			{
				if ($('div.price p.total', this).is('*'))
				{
					$(this).height(h + 11).css({'overflow':'visible'});
				}
				else
				{
					$(this).height(h);
				}
			}
		}
	});

});
