/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/
 
viewSeconds = 3.5;
firstSlide = 1;
paused = 0;

function slideSwitch(whichWay) {
	clearTimeout(playSlideshow);
	
	var $active = $('#slideshow div.active');
	if (whichWay == "back") {
		if ( $active.length == 0 ) $active = $('#slideshow div:first');
		var $next = $active.prev().length ? $active.prev() : $('#slideshow div:last');
	} else {
		if ( $active.length == 0 ) $active = $('#slideshow div:last');
		var $next = $active.next().length ? $active.next() : $('#slideshow div:first');
	}
	
	$active.addClass('last-active') .animate({opacity : 0.0}, 500);
	$next.css({opacity: 0.0}) .addClass('active') .animate({opacity: 1.0}, 500, function() {
		$active.removeClass('active last-active');
	});
	
	if (firstSlide == 1) {
		firstSlide = 0;
		if (document.getElementById('ssopen')) document.getElementById('slideshow').removeChild(document.getElementById('ssopen'));
	}
	
	if (paused == 0) playSlideshow = setTimeout( "slideSwitch()", viewSeconds * 1000 );
}

$(function() {
	playSlideshow = setTimeout( "slideSwitch()", viewSeconds * 1000 );
	
	$("#slideshow:first").hover(function() {
		paused = 1;
		clearTimeout(playSlideshow);
		document.getElementById("paused").style.display = "block";
	}, function() {
		paused = 0;
		playSlideshow = setTimeout( "slideSwitch()", viewSeconds * 1000 );
		document.getElementById("paused").style.display = "none";
	});
	
	$(".cyclearrow").hover(function() {
		paused = 1;
		clearTimeout(playSlideshow);
		document.getElementById("paused").style.display = "block";
	}, function() {
		paused = 0;
		playSlideshow = setTimeout( "slideSwitch()", viewSeconds * 1000 );
		document.getElementById("paused").style.display = "none";
	});
});
