// JavaScript Document
// Versione 1.0
// Creato il 27/07/2011
// Autore Andrea Furlan

function SlideshowWrapper(){
	this.set = function(idContainer,imgPath,imgList) {
		this.container = $('#'+idContainer);
		this.imgPath = imgPath;
		this.imgList = imgList;
		this.currentImgId = 0;
		
		for (i=1;i<this.imgList.length;i++){
			this.container.append('<img src="'+this.imgPath+imgList[i]+'" style="display:none">');
		}
		this.imgs = this.container.children('img');
	}
	
	this.next = function() {
		this.oldImgId = this.currentImgId;
		this.currentImgId = (this.currentImgId+1)%this.imgList.length;
		$(this.imgs[this.oldImgId]).fadeOut(2000);
		$(this.imgs[this.currentImgId]).fadeIn(2000);
	}
	
	this.setAndStart = function(idContainer,imgPath,imgList) {
		this.set(idContainer,imgPath,imgList);
		this.setNextStep();
	}
	
	this.nextStep = function() {
		this.next();
		this.setNextStep();
	}
	
	this.setNextStep = function() {
		setTimeout('Slideshow.nextStep()',5000);
	}
}

var Slideshow = new SlideshowWrapper();
