
/**
 * @author Dave Mauro
 */

var shortWait = 400;
var longWait = 3500;
var shortTimer;
var longTimer;
var fadeInSpeed = 2500;
var fadeOutSpeed = 1000;
var opacityDelay = 200;
var finalFadeSpeed = 1000;

var currentPiece = 1;

$(document).ready(function()
{
	pauseSlideshow();
	$('#poem_bg').css({opacity:0}).stop().animate({"opacity": .9}, 600, "swing", function() {
		scrollTopPiece();
	});
});

function scrollTopPiece()
{
	$('#poem'+currentPiece).removeClass("hidden").css({opacity:0}).stop().animate({"left": 50, "opacity": 1}, fadeInSpeed, "swing");
	currentPiece++;
	shortTimer = setTimeout("scrollBottomPiece()", shortWait);
}

function scrollBottomPiece()
{
	$('#poem'+currentPiece).removeClass("hidden").css({opacity:0}).stop().animate({"left": 290, "opacity": 1}, fadeInSpeed, "swing", function() {
		longTimer = (currentPiece == 7) ? setTimeout("finishPoem()", longWait) : setTimeout("scrollNext()", longWait);
	});
	currentPiece++;
}

function scrollNext()
{
	var topPiece = currentPiece-2;
	var bottomPiece = currentPiece-1;
	$('#poem'+(topPiece)).stop().animate({"opacity": 0}, fadeOutSpeed, "swing", function() {
		$('#poem'+(topPiece)).addClass("hidden");
	});
	$('#poem'+(bottomPiece)).stop().animate({"opacity": 0}, fadeOutSpeed, "swing", function() {
		$('#poem'+(bottomPiece)).addClass("hidden");
		scrollTopPiece();
	});
}

function finishPoem()
{
	var topPiece = currentPiece-2;
	var bottomPiece = currentPiece-1;
	$('#poem'+(topPiece)).stop().animate({"opacity": 0}, finalFadeSpeed, "swing", function() {
		$('#poem'+(topPiece)).addClass("hidden");
	});
	$('#poem'+(bottomPiece)).stop().animate({"opacity": 0}, finalFadeSpeed, "swing", function() {
		$('#poem'+(bottomPiece)).addClass("hidden");
	});
	$('#poem_bg').stop().animate({"opacity": 0}, finalFadeSpeed, "swing", startSlideshow());
	
}
