// JavaScript Document
var lastImgUrl = '';
var thumbIdx = 0;
var navHeight = 86;
var contentHeight = 199;
var contentSpanHeight = 200;
	
function getPhoto(me, imgurl) {
	if (lastImgUrl != imgurl) {
		lastImgUrl = imgurl;
		thumbIdx = $(".thumbnails a").index(me);
		$(".thumbnails a").removeClass("selected");
		me.addClass("selected");
		$("#photomask").animate({"width": 0} , 200, 0 , loadPhoto);
		$("#photoDesc").animate({"width": 0} , 200);
	}
}

function loadPhoto() {
	$("#photomask").hide();
	$("#photoDesc").hide();
	$("#loading").show();
	$("#loading").html('<img src="tutorial/images/asteroids.gif" />');
	$("#photomask").load(lastImgUrl, {}, photoLoaded);
}

function photoLoaded() {
	var txt = $("#big_show .hidden").html();
	$("#photoDesc > div").html(txt);
	$(".photo img").load(function(){
		//alert("loaded");
		$("#loading").hide();
		$("#photomask").show();
		$("#photoDesc").show();
		$("#photomask").animate({"width": "650px"} , 200);
		$("#photoDesc").animate({"width": "300px"} , 200);
		$(".photo img").click(hideSlideShow);
		
	});
}

function sizeUp() {
	$("#big_show").load("slideshow/slides/"+URLSegment, {}, showSlideShow);
	$("#prev-next").hide();
	$("#navi").animate({"height": 0}, 300);
	$("#content").animate({"height": 480+10 + "px"} , 300);
}
		
function doafter() {
	//$("#big_show").load("slideshow/slides/"+URLSegment, {}, show);
}

function showSlideShow() {
	var txt = $("#big_show .hidden").html();
	$("#photoDesc > div").html(txt);
	$("#big_show").show();
	$("#thumbmask").animate({"width": "325px"}, 200);
	$(".photo img").load(function(){
		$(".photo img").click(hideSlideShow);
		thumbIdx = 0;
		$("#photomask").animate({"width": "650px"}, 200);
	});
	bindNavigation();
	
}

function hideSlideShow() {
	$(".images img").show();
	$("#thumbmask").animate({"width": 0}, 200, sizeDown);
	$("#photomask").animate({"width": 0}, 200, 0, doafter2);
}

function doafter2() {
	$("#big_show").hide();
	$(".span-1, .span-2, .span-3, .span-4, .span-5, .span-6").each(function() {
		$(this).show();
		$(this).animate({"height": contentSpanHeight+"px"} , 300);
	});
}
function sizeDown() {
$(".pager").show();
	$("#navi").animate({"height": navHeight+"px"}, 300);
	$("#content").animate({"height": contentHeight + "px"} , 300);
	$("#see_more").show();
	
}
function setHeights() {
	navHeight = $("#navi").height();
	contentHeight = $("#content").height();
}

function bindNavigation() {	
	n = ($('.thumbnails a').length)-1;
	$(".bw").click(
		function() {
			if((thumbIdx-1) < 0)
				elToLoad = $('.thumbnails a:eq('+(n)+')');
			else
				elToLoad = $('.thumbnails a:eq('+(thumbIdx-1)+')');

			getPhoto(elToLoad, elToLoad.attr("rel"));
		}
	);
	$(".ff").click(
		function() {
			if((thumbIdx+1) > n)
				elToLoad = $('.thumbnails a:eq(0)');
			else
				elToLoad = $('.thumbnails a:eq('+(thumbIdx+1)+')');

			getPhoto(elToLoad, elToLoad.attr("rel"));
		}
	);
}

$(window).load(function() {
	$("#content").height($('#content').height());
	$(".roll_inner").hover(
		function() { $(this).children(".shortDescOverview").animate({"height": "155px"},{ queue:false, duration:200 });},
		function() { $(this).children(".shortDescOverview").animate({"height": 0},{ queue:false, duration:200 });}
	);
	$(".articleTitle").hover(
		function() { $(this).prev(".roll_inner").children(".shortDescOverview").animate({"height": "155px"},{ queue:false, duration:200 });},
		function() { $(this).prev(".roll_inner").children(".shortDescOverview").animate({"height": "0px"},{ queue:false, duration:200 });}

	);
	
	$("#big_show").hide();
	
	if(SlideOnOff == 1){ //Open Slideshow
		$("#see_more, .images img").click(
			function() {		
				//$(".span-1, .span-2, .span-3, .span-4, .span-5, .span-6").fadeOut(250);
				$time = 300;
				setHeights();
				$(".span-1, .span-2, .span-3, .span-4, .span-5, .span-6").each(function() {
					if ($(this).height() > contentSpanHeight) contentSpanHeight = $(this).height();
					$(this).animate({"height": 0} , $time,0,function(){$(this).hide();});
					//$time += 200;
				});
				//alert(contentSpanHeight);
				sizeUp();
				$("#see_more").hide();
				$(".pager").hide();
			}

		);
	};


});
