/*
 * Effects Library for controlling javascript "Slideshow" animation
 * Requires Scriptaculous
 */

// Object to store information relating to a "Scene" in an animated slide show
function AnimationScene(pElement, pInterval) {
	this.element = pElement;
	this.interval = pInterval;
}

// Animation engine - executes animation, sets up looping through scenes etc..
function Animation(pScenes, pStartFrame, pDuration) {
	this.scenes = pScenes;
	this.currentFrame = pStartFrame;
	this.nextFrame = this.getNextFrame();
	this.effectDuration = pDuration;
}

Animation.prototype.getNextFrame = function() {
	return ((this.currentFrame + 1) > this.scenes.length-1) ? 0 : (this.currentFrame + 1) ;
}

Animation.prototype.fade = function(pObj1, pObj2) {
	Effect.Fade($(pObj1), {from:1.0, to:0.0, duration:this.effectDuration});
	Effect.Appear($(pObj2), {from:0.0, to:1.0, duration:this.effectDuration});
}

Animation.prototype.createEffect = function() {
	var self = this;
	this.fade(this.scenes[this.currentFrame].element, this.scenes[this.nextFrame].element);

	this.currentFrame = this.nextFrame;
	this.nextFrame = this.getNextFrame();

	var to = setTimeout(function(){self.createEffect()}, this.scenes[this.currentFrame].interval);
}

Animation.prototype.start = function() {
	var self = this;

	var to = setTimeout(function(){self.createEffect()}, this.scenes[this.currentFrame].interval);
}
