var PHOTO_TOUR_URL;

$(function()
{
	$("a[href=/photo-tour]").attr('href', "/layout/set/gallery-layout/photo-tour/hotel-tour").attr("target", "_blank");
	if ($("body.gallery-layout").length) {
		$ss = $("#slideshow");
		$ss.cycle(
		{
			fx: "fade",
			timeout: 6000,
			speed: 500,
			next: $("a.btn_next"),
			prev: $("a.btn_prev"),
			after: changeCaption
		});
		$("p.caption").text($("#slideshow img:eq(0)").attr("alt"));
		$("p.progress").html("Image <span>1</span> of "+$("#slideshow img").length);
	}
	$("a.btn_pause").click(function()
	{
		$("#slideshow").cycle("pause");
		$(this).hide();
		$("a.btn_play").show();
		return false;
	});
	$("a.btn_play").click(function(){
		$("#slideshow").cycle("resume");
		$(this).hide();
		$("a.btn_pause").show();
		return false;
	});
	/*$("ul.nav-tabs li").hover(function()
	{
		$(this).addClass("active");
		$("ul", $(this)).slideDown(300);
	}, function()
	{
		$(this).removeClass("active");
		$("ul", $(this)).slideUp(300);
	});
	
	$("ul.nav-tabs li").bind("mouseenter",function(){
		$(this).children("ul").slideToggle(400);
	}).bind("mouseleave",function(){
		$(this).children("ul").slideToggle(400);
	});
	
	$("ul.galleries a").click(function()
	{	
		$("ul", $("ul.nav-tabs li.active")).slideUp(300);
		$("ul.nav-tabs li.active").removeClass("active");
		loadSlideshow($(this).attr("href"));
		return false;
	}); */
	
	
	$("ul.nav-tabs li.nav-tab").bind("mouseenter",function(){
		$("div", this).show();
	}).bind("mouseleave",function(evt){
		$("div", this).hide();
	})
	
	$("ul.galleries a").click(function()
	{
		$("ul", $("ul.nav-tabs li.active")).show();
		$("ul.nav-tabs li.active").removeClass("active");
		loadSlideshow($(this).attr("href"));
		return false;
	});
	
	//load slideshow on start
	start();
});

function start()
{
	var myFile = document.location.toString();
    if (myFile.match('#'))
    {
		var hash = myFile.split('#')[1];
		if(hash == "spa")
			$('ul.galleries a:last').trigger('click');
		else
			$('ul.galleries a:first').trigger('click');
	}
}

function changeCaption()
{
	$("p.progress span").html(($("#slideshow img").index(this)+1));
	$("p.caption").text(this.alt);
}

function loadSlideshow(url)
{
	$("#slideshow").html("<p style='text-align:center;height:400px;line-height:400px;color:white;'>LOADING IMAGES...</p>");
	$("#slideshow").css({"background-color":"#976D47"});
	$("#slideshow").load(url, function()
	{
		$ss = $("#slideshow");
		$ss.cycle(
		{
			fx: "fade",
			timeout: 6000,
			speed: 500,
			next: $("a.btn_next"),
			prev: $("a.btn_prev"),
			after: changeCaption
		});
		$("p.caption").text($("#slideshow img:eq(0)").attr("alt"));
		$("p.progress").html("Image <span>1</span> of "+$("#slideshow img").length);		
	});
}

