/********************************************************************* 
v..Slideshow
http://macvek.pl
*/

vDotsSlideshow = function(slides,node,fadeTime,pauseTime) {

	this.slides = slides;	
	this.node = node;
	this.fadeTime = fadeTime;
	this.pauseTime = pauseTime;
	
	if (!this.slides.length) return;
	this.index = 0;
	
	
	this.id = 'vDotsSlideshow_'+Math.round((Math.random()*10000));
	this.loadBoxId = this.id+'_background';

	var loadboxSrc = '<img id="'+this.loadBoxId+'" src="" style="visibility:hidden;position:absolute;top:0px;left:0px;"/>';
	
	var bodyNode = $$('body')[0];
	if (!bodyNode) return;
	
	bodyNode.insert(loadboxSrc,{position:"before"});
	this.loadBox = $(this.loadBoxId);
	this.loadBox.observe('load',this.preLoad.bind(this));
	this.preLoad();	
	
	return true;
}

vDotsSlideshow.prototype.fadeIn = function() {
	if (++this.index == this.slides.length) this.index = 0;
	this.node.setStyle({ backgroundImage: 'url('+this.slides[this.index]+')' });
	
	new Effect.Opacity(this.node, { from: 0, to: 1, duration: this.fadeTime});
}

vDotsSlideshow.prototype.fadeOut = function() {
	var nextFunc = this.fadeIn.bind(this);
	
	new Effect.Opacity(this.node, { from: 1, to: 0, duration: this.fadeTime, afterFinish: nextFunc});
}

vDotsSlideshow.prototype.preLoad = function() {
	if (this.index == this.slides.length) {
		this.index = 0;
		this.node.parent = this;

		var func = this.fadeOut.bind(this);
		this.player = new PeriodicalExecuter(func,this.pauseTime + this.fadeTime*2);

		return;
	}
	this.loadBox.src = this.slides[this.index++];
}


