// JavaScript Document

/***********************************************
* TDSlideShow- Displays a series of elements as a slide show
***********************************************/

function slideShow(slidePrefix, slideIndex, slideCount, delay, repeatFlag) {
	if (self.cycle) {clearInterval(cycle);}
	theDisplayedSlideIndex = Math.max(slideIndex - 1, 0);
	theSlidePrefix = slidePrefix;
	theNextSlideIndex = slideIndex;
	theSlideCount = slideCount;
	theDelay = delay;
	theRepeatFlag = repeatFlag;
	playStatus = 1;
	serializedStatus = 0;
	cycle = setInterval('fadeSlides(); theNextSlideIndex++;', theDelay);
}

function pauseSlideShow() {
	if (playStatus == 1) {
		clearInterval(cycle);
		playStatus = 0;
	}
}

function playSlideShow() {
	if (playStatus == 0) {
		playStatus = 1;
		if (theDisplayedSlideIndex >= theSlideCount) {
			theNextSlideIndex = 0;
		}
		else {
			theNextSlideIndex = theDisplayedSlideIndex + 1;
		}
		if (serializedStatus == 1) {
			deserializeSlides();
			theNextSlideIndex = 0;
		}
		slideShow(theSlidePrefix, theNextSlideIndex, theSlideCount, theDelay, theRepeatFlag);
	}
}

function changeSlide(increment) {
	if (playStatus == 1) {
		pauseSlideShow();
	}
	theNextSlideIndex = theDisplayedSlideIndex + increment;
	theNextSlideIndex = Math.max(theNextSlideIndex, 0);
	theNextSlideIndex = Math.min(theNextSlideIndex, theSlideCount);
	fadeSlides();
}

function fadeSlides() {
	if (theRepeatFlag != 1 && (theNextSlideIndex >= theSlideCount)) {
		pauseSlideShow();
		return true;
	}
	else {
		theNextSlideIndex = (theNextSlideIndex % theSlideCount);
		var theNextSlideID = theSlidePrefix + theNextSlideIndex;
		var theDisplayedSlideID = theSlidePrefix + theDisplayedSlideIndex;
		Effect.Fade(theDisplayedSlideID, {duration:0.1});
		Effect.Appear(theNextSlideID);
		theDisplayedSlideIndex = theNextSlideIndex;
	}
} 

function serializeSlides() {
	pauseSlideShow();
	theContainer = document.getElementById('lb_story_static');
	theContainer.style.overflow = "auto"; 
	for (var i=0; i < theSlideCount; i++) {
		theDisplayID = theSlidePrefix + i;  
		theSlide = document.getElementById(theDisplayID);
		theSlide.style.display = "block";
	}
	serializedStatus = 1;
}
		
function deserializeSlides() {
	pauseSlideShow();
	theContainer = document.getElementById('lb_story_static');
	theContainer.style.overflow = "hidden"; 
	for (var i=0; i < theSlideCount; i++) {
		theDisplayID = theSlidePrefix + i;  
		theSlide = document.getElementById(theDisplayID);
		theSlide.style.display = "none";
	}
	serializedStatus = 0;
}
	
