// JavaScript Document
// Versione 1.1
// Creato il 10/1/2011
// Autore Andrea Furlan

function SlideshowWrapper(){
	this.currentImgId = 0;		//Variabile di default per segnalare qual è l'immagine forzata nell'html
	this.childFilter = 'img';	//Selettore jquery per identificare gli oggetti che si alternano
	this.imgPath = '';			//percorso dove cercare le immagini, se non è compreso nei nomifile
	this.codeFormat = '<img src="%s" style="display:none">';
	
	this.set = function(idContainer,imgList) {
		this.container = $('#'+idContainer);
		this.imgList = imgList;
		
		for (i=1;i<this.imgList.length;i++){
			//this.container.append('<img src="'+this.imgPath+imgList[i]+'" style="display:none">');
			this.container.append(this.codeFormat.replace('%s',this.imgPath+imgList[i]));
		}
		
		this.imgs = this.container.children(this.childFilter);
	}
	
	this.setImgPath = function(path){
		this.imgPath = path;
	}
	
	this.setChildFilter = function(filter){
		this.childFilter = filter;
	}
	
	this.setCodeFormat = function(code){
		this.codeFormat = code;
	}
	
	this.setCallback = function(func){
		this.callBack = func;
	}
	
	this.next = function() {
		this.oldImgId = this.currentImgId;
		this.currentImgId = (this.currentImgId+1)%this.imgList.length;
		$(this.imgs[this.oldImgId]).fadeOut(1500);
		$(this.imgs[this.currentImgId]).fadeIn(1500);
		this.callBack.call('',this.currentImgId,this.oldImgId);
	}
	
	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();
