/*********************************************************

	JavaScript SlideShow

	author: Stephan Jorek

	(c) 2006 - @rtplan[21] webconcepts & solutions GmbH
*********************************************************/

var slide = null;

var Slideshow = function(elems) {
	if (elems.length > 1) {
		this.elements = elems;
		this.current = 0;
		this.visualObj = null;
		this.running = false;
		this.working = false;
		this.options = {
			fps: 25,
			duration: 2,
			delay: 5
		};
		this.run();
	}
}

Slideshow.prototype = {

	run: function() {
		if (this.working == false) {

			this.running = true;
			this.working = true;

			if (this.current < (this.elements.length-1)) {
				this.current += 1;
				var opts = this.options;
				opts.afterFinish = bind(this.callback,this);
				appear(this.elements[this.current],opts);
			} else {
				for (var i=1; i<this.elements.length-1; i++) {
					hideElement(this.elements[i]);
				}
				var opts = this.options;
				opts.afterFinish = bind(this.callback,this);
				fade(this.elements[this.current],opts);
				this.current = 0;
			}
		}
	},

	callback: function() {
		this.working = false;
		if (this.running==true) {
			this.run();
		}
	},

	stop: function() {
		this.running = false;
	}
};

var initiateSlideshow = function() {
	slide = new Slideshow(getElementsByTagAndClassName('div','slideshow-element'));
}

addLoadEvent(initiateSlideshow);