var show_hotels = 4;

$(function()
{
	$("#logo_hd img").mouseover(function(){
		$(this).attr("src", "img/logo_hotel_direct_over.gif");
	}).mouseout(function(){
		$(this).attr("src", "img/logo_hotel_direct.gif");
	});
	
	$('#main_image').cycle({ 
		fx:     'fade', 
		speed:  1000, 
		timeout: 5000, 
		pager:  '#thumbnails', 
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return '#thumbnails li:eq(' + idx + ') a'; 
		}
	});
	
	$('#main_image').cycle('pause');
	
	$('#pause').click(function(){
		$('#main_image').cycle('pause');
		$("#pause").hide();
		$("#resume").show();
		return false;
	}).mouseover(function(){
		$('#pause img').attr("src", "img/button_pause_on.gif");
	}).mouseout(function(){
		$('#pause img').attr("src", "img/button_pause.gif");
	});
	
	$('#resume').click(function(){
		$('#main_image').cycle('resume');
		$("#resume").hide();
		$("#pause").show();
		return false;
	}).mouseover(function(){
		$('#resume img').attr("src", "img/button_slideshow_on.gif");
	}).mouseout(function(){
		$('#resume img').attr("src", "img/button_slideshow.gif");
	});
	
	$("#submit2.hotel").mouseover(function(){
		$(this).attr("src", "img/button_book_now_on.gif");
	}).mouseout(function(){
		$(this).attr("src", "img/button_book_now.gif");
	});
	
	rows = 0;
	$("div.room_row").each(function(){
		rows++;
		if (rows > show_hotels)
		{
			$(this).hide();
		}
		if (rows > show_hotels)
		{
			$(this).find("div.room_title p span").show();
			$(this).find("div.room_title p span a").html("show more");
			$(this).find("div.room_title p span a").addClass("down");
		}
	});
	
	if (rows <= show_hotels)
	{
		$("div.more p a").hide();
	}
	
	$("div.more p a").click(function(){
		row = $(this).attr("name");
		if ($(this).html() == "show more")
		{
			$(this).html("show less");
			$(this).removeClass("down");
			$("div.room_row").show();
		}
		else if ($(this).html() == "show less")
		{
			$(this).html("show more");
			$(this).addClass("down");
			rows = 0;
			$("div.room_row").each(function(){
				rows++;
				if (rows > show_hotels)
				{
					$(this).hide();
				}
			});
		}
		return false;
	});
	
	//$("#breakdown p").hide();
	
	$("div.room_row select").change(function(){
		calculateCost();
	});
	
	$("a.expand").click(function(){
		info = $(this).attr("name");
		
		if (info != '')
		{
			if ($(this).hasClass("open"))
			{
				$("#search div.room_info_price").html("");
				$(this).parent().parent().removeClass("top");
				$("#blackout").removeClass("lighter");
				$("#blackout").hide();
				$("select").removeClass("ie6");
				$("#info_" + info).hide();
				$("#price_" + info).hide();
				$(this).removeClass("open");
				$(this).parent().next().next().next("a.close").hide();
			}
			else
			{
				$("#search div.room_info_price").html($("#form_bottom").html());
				$(this).parent().parent().addClass("top");
				$("#blackout").show();
				$("#blackout").addClass("lighter");
				$("select").addClass("ie6");
				$("select#select_" + info).removeClass("ie6");
				$("#info_" + info).show();
				$("#price_" + info).show();
				$(this).addClass("open");
				$(this).parent().next().next().next("a.close").show();
			}
		}
		return false;
	});
	
	$("div.room_row a.close").click(function(){
		$("#search div.room_info_price").html("");
		$(this).parent().removeClass("top");
		$("#blackout").removeClass("lighter");
		$("#blackout").hide();
		$("select").removeClass("ie6");
		$("#info_" + info).hide();
		$("#price_" + info).hide();
		$("a.expand").removeClass("open");
		$("div.room_row a.close").hide();
		return false;
	});
	
	calculateCost();
	
	$("a.map").click(function(){
		openWindow($(this).attr("href"), 799, 551, 'no');
		return false;
	});

	$("a.slideshow").click(function(){
		openWindow($(this).attr("href"), 955, 488, 'no');
		return false;
	});

	
	//$("#breakdown p a").click(function(){
	//	openWindow($(this).attr("href"), 520, 220, 'no');
	//	return false;
	//});
});

function calculateCost()
{
	total = 0;
	$("div.room_row select").each(function(){
		cost = $(this).attr("title") * $(this).val();
		total = parseInt(total + cost);
	});
	if ((total == 0) || (total == ''))
	{
		$("p.price strong").html("000");
		//$("#breakdown p").hide();
	}
	else
	{
		$("p.price strong").html(total);
		//$("#breakdown p").show();
	}
}
