$(function()
{
	$("#top-images .photo-tour").mouseenter(function() {
			$(this).animate({"height": "100px"}, 1000);
		}).mouseleave( 
		function() {
			$(this).animate({ "height": "27px"}, 1000);
		}
	);
	
	$("#top-images .photo-tour ul li a, a[name='omni_gallery_nav'], a[name='omni_gallery_footer']").click(function(evt){		
		var slideshowURL = "/layout/set/slideshow_images/"+$(this).attr("href");
		
		evt.preventDefault();
		$("#top-images .slides").cycle("stop");
		$("#modal-layer").fadeIn(function(){
			//ie 6 specific. To hide the form elements of the quick-res
			if ($.browser.msie == true && $.browser.version.substring(0,1) == "6") {
				var iFrame = document.createElement("iframe");
				$(iFrame).attr({
					"name": "i_hate_ie_6",
					"id": "i_hate_ie_6"
				}).css({
					"width":$("#quick-res").width()+"px",
					"height": $("#quick-res").height()+"px",
					"position": "absolute",
					"zIndex": "998"
				}).appendTo("body");
				var iFramePos = $("#quick-res").offset();
				$("#i_hate_ie_6").css({
					top: iFramePos.top+"px",
					left: iFramePos.left+"px"
				})
			}
			$("#slideshow-modal").show();
			loadSlideshow(slideshowURL);
			
			$("a.btn_close").click(function(){
				$("#slideshow-modal").hide();
				$("#modal-layer").fadeOut();
				$("#i_hate_ie_6").remove();
				return false;
			});
		});
		return false;
	});

	$("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.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;
	});
});

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":"#8eb6d8"});
	$("#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);		
	});
}