$(function()
{
	
	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");
		$("div", $(this)).show();
	}, function()
	{
		$(this).removeClass("active");
		$("div", $(this)).hide();
	});
	$("ul.galleries a").click(function()
	{
		loadSlideshow($(this).attr("href"));
		return false;
	});
});

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":"#0198a1"});
	$("#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);
	});
}