$(function()
{
	setSunday(1);
	setGuests(2);
	getCurrency();
	resetAdvancedSearch(0);
	showKidsAge();
	
	var browser = 0;
	if($.browser.msie && $.browser.version=="7.0")
	{
		browser = 7;
		$('.search_button').css({'bottom':'4px'});
	}
	if($.browser.msie && $.browser.version=="8.0")
	{
		browser = 8;
		$('.search_button').css({'bottom':'4px'});
	}

	$("#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");
	});

	$('#room_exp').click(function(e){
		openWindow($(this).attr('href'),'700','600','y');
		e.preventDefault();
	});
	
	$(".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");
	});
	
	$(".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();
		}
		$('select.room').each(function(){
			if (!$(this).parent().is(':visible'))
			{
				$(this).get(0).selectedIndex = 0;
			}
		});
		if ($(this).val() > 1)
		{
			$("#roomtype1").parent().find('p.sleeps').html('Room 1 sleeps');
			$('div#search div#search-form div.advanced').css({'margin-top':'11px'});
			$('#accommodates').show();
			setGuests(3);
		}
		else
		{
			$("#roomtype1").parent().find('p.sleeps').html('Room sleeps');
			$('div#search div#search-form div.advanced').css({'margin-top':'38px'});
			$('#accommodates').hide();
		}
		showHideKids();
	});
	
	$(".room").change(function(){
		showHideKids();
		setGuests(3);
	});
	
	$(".kidsage").change(function(){
		setGuests(3);
	});
	
	$("#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).css({'color':'#666'});
		$("#postcode").val("Postcode").css({'color':'#666'});
		$(this).attr("selectedIndex", sel);
		
		$(this).css({'color':'#000'});
		if (sel == '' || sel == '%%')
		{
			$(this).css({'color':'#666'});
		}
	}).mousedown(function(){
		$(this).css({'color':'#000'});
	});
	
	$(".advanced_2").css({'color':'#666'});
	$(".advanced_2 option:selected").each(function(){
		sel = $(this).val();
		$(this).parent().css({'color':'#000'});
		if (sel == '' || sel == '%%')
		{
			$(this).parent().css({'color':'#666'});
		}
	});
	
	$("#show_search").click(function(){
		$('#advanced_search').slideToggle('fast', function(){
			if ($(this).is(":visible"))
			{
				document.cookie = "advanced=1";
				if (browser == 7)
				{
					$('.search_button').css({'top':'328px'});
				}
			}
			else
			{
				document.cookie = "advanced=0";
				if (browser == 7)
				{
					$('.search_button').css({'top':'106px'});
				}
			}
			if (browser == 8)
			{
				$('.search_button').css({'bottom':'4px'});
			}
		});
		return false;
	});
	
	$("#postcode").click(function(){
		if ($(this).val() == "Postcode")
			$(this).val("").css({'color':'#666'});
	}).blur(function(){
		if ($(this).val() == "")
			$(this).val("Postcode").css({'color':'#000'});
		else
			$(".advanced_2").attr("selectedIndex", 0);
	}).css({'color':'#666'});
	
	$(".closest_advanced").change(function(){
		sel = $(this).attr("selectedIndex");
		$(".closest_advanced").attr("selectedIndex", 0);
		$("#closest_postcode").val("Insert postcode");
		$("#closest_street").val("Insert street name");
		$(this).attr("selectedIndex", sel);
	});
	
	$("#closest_postcode").click(function(){
		if ($(this).val() == "Insert postcode")
			$(this).val("");
	});
	$("#closest_postcode").blur(function(){
		if ($(this).val() == "")
			$(this).val("Insert postcode");
		else
		{
			$(".closest_advanced").attr("selectedIndex", 0);
			$("#closest_street").val("Insert street name");
		}
	});
	
	$("#closest_street").click(function(){
		if ($(this).val() == "Insert street name")
			$(this).val("");
	});
	$("#closest_street").blur(function(){
		if ($(this).val() == "")
			$(this).val("Insert street name");
		else
		{
			$(".closest_advanced").attr("selectedIndex", 0);
			$("#closest_postcode").val("Insert postcode");
		}
	});
	
	$(".closest_advanced").change(function(){
		if ($(this).val() != "")
		{
			var redirect = $(this).val();
			$(this).val('');
			//ConversionCount();
			location.href = redirect;
		}
	});
	
	$("a#postcode-go").click(function(){
		if (($("#closest_postcode").val() != "") && ($("#closest_postcode").val() != "Insert postcode"))
			location.href = $("#closest_postcode_url").val() + $("#closest_postcode").val();
		return false;
	});
	
	$("a#street-go").click(function(){
		if (($("#closest_street").val() != "") && ($("#closest_street").val() != "Insert street name"))
			location.href = $("#closest_street_url").val() + $("#closest_street").val();
		return false;
	});
	
	$("#home_form").submit(function(){
		return checkHomeSearch();
	});
	
	$("#city_map area").mouseover(function(){
		if (!$(this).hasClass('nomap'))
		{
			$("#city_map_img").attr("src", "img/" + $(this).attr("name").toLowerCase() + "_city_map_" + $(this).attr("id") + ".gif");
		}
	}).mouseout(function(){
		if (!$(this).hasClass('nomap'))
		{
			$("#city_map_img").attr("src", "img/city_map_" + $(this).attr("name").toLowerCase() + ".gif");
		}
	});
	
	$('div.viewed').mouseover(function(){
		$('p', this).addClass('underline').css({'color':'#333'});
	}).mouseout(function(){
		$('p', this).removeClass('underline').css({'color':'#3a9938'});
	}).click(function(){
		//doGoal2($('a', this).attr('href'));
		document.location.href = $('a', this).attr('href');
	});
	
	$('div.viewed-more').mouseover(function(){
		$('p.name', this).addClass('underline').css({'color':'#333'});
	}).mouseout(function(){
		$('p.name', this).removeClass('underline').css({'color':'#3a9938'});
	}).click(function(){
		//doGoal2($('a', this).attr('href'));
		document.location.href = $('a', this).attr('href');
	});
	
	$('div.details').mouseover(function(){
		$(this).addClass('over');
	}).mouseout(function(){
		$(this).removeClass('over');
	}).click(function(){
		//doGoal2($('a', this).attr('href'));
		document.location.href = $('a', this).attr('href');
	});
	
	$('div#near div.street p a').click(function(){
		$('input#closest_street, a#street-go').toggle();
		return false;
	});
	
	$('div#banners a').each(function(){
		if ($('img', this).attr('src') == 'img/hidden_gems.jpg')
		{
			$(this).mouseover(function(){
				$('img', this).attr('src', 'img/hidden_gems_roll.jpg');
			}).mouseout(function(){
				$('img', this).attr('src', 'img/hidden_gems.jpg');
			});
		}
		else if ($('img', this).attr('src') == 'img/guest_reviews.jpg')
		{
			$(this).mouseover(function(){
				$('img', this).attr('src', 'img/guest_reviews_roll.jpg');
			}).mouseout(function(){
				$('img', this).attr('src', 'img/guest_reviews.jpg');
			});
		}
		else if ($('img', this).attr('src') == 'img/tv_banner.jpg')
		{
			$(this).addClass('tvadvert');
		}
	});

	getLastViewed();
});
