var scroller;
var scrollerwhich;
function ScrollIt()
{
	var e = document.getElementById( scrollerwhich );
	var top = parseInt( e.style.top );
	if ( top < -e.offsetHeight )
		top = e.offsetParent.offsetHeight - 12;
	e.style.top = (top - 1) + "px";
}

function Scroller( which )
{
	scrollerwhich = which + "mover";
	document.getElementById( scrollerwhich ).style.top = (document.getElementById( scrollerwhich ).offsetParent.offsetHeight - 12) + "px"
 	scroller = setInterval( ScrollIt, 80 );
 	
 	if ( GetElement( which + "all" ) != null )
 		which = which + "all";
	$( "#" + which ).mouseover( function() { clearInterval( scroller ); } );
	$( "#" + which ).mouseout( function() { scroller = setInterval( ScrollIt, 80 ); } );
}

var slideshowrotator,
	maxphotoheight;
function InitSlideShow()
{
	// add click method to thumbs
	$("#slideshowthumbs").children( "div" ).not(".controller").bind("click", 
		function()
		{ 
			clearInterval( slideshowrotator );
			slideshowrotator = 0;
			SlideShowShowSlide( $(this) ); 
			
			if ( $("#pause").css( "display" ) != "none" )
			{
				$("#pause").hide();
				$("#play").show();
			}
		});
	
	// add click method to controllers
	$("#slideshowthumbs").children( "#play" ).click( function() { SlideShowPlay(); } );
	$("#slideshowthumbs").children( "#pause" ).click( function() { SlideShowPause(); } );
	
	SlideShowPlay();
}

function SlideShowPause()
{
	clearInterval( slideshowrotator );
	slideshowrotator = 0;
	$("#pause").hide();
	$("#play").show();
	return false;
}

function SlideShowPlay()
{
	clearInterval( slideshowrotator );
	slideshowrotator = 0;
	slideshowrotator = setInterval( NextSlide, 4000 );
	NextSlide();
	$("#play").hide();
	$("#pause").show();
	return false;
}

function NextSlide()
{
	var current = $("#slideshowthumbs").find( "div.current" );
	
	if ( current.next().not( ".controller" ).length > 0 )
		 SlideShowShowSlide( current.next() );
	else
		 SlideShowShowSlide( $("#slideshowthumbs").find( "div" ).eq( 0 ) );
}

function SlideShowShowSlide( div )
{
	$("#slideshowthumbs").find( "div" ).removeClass( "current" );
	div.addClass( "current" );

	$("#slideshowphoto").empty();
	$("#slideshowphoto").append( div.find( "a" ).children().clone() );


	if ( !maxphotoheight || $("#slideshowphoto img").height() > maxphotoheight )
		maxphotoheight = $("#slideshowphoto img").height() + $("#slideshowphoto div.caption").height();

	$("#slideshowphoto").height( maxphotoheight + 10 );
	
	return false;
}