var sliders = new Array();

function so_init() {
                var _self = this;

	if(!this.d.getElementById || !this.d.createElement)return;

	this.imgs = this.d.getElementById(this.divslide).getElementsByTagName("img");

	for(i=1;i<this.imgs.length;i++) this.imgs[i].xOpacity = 0;
	this.imgs[0].style.display = "block";
	this.imgs[0].xOpacity = .99;
	setTimeout(function(){_self.so_xfade();},this.tempovisualizzazione);
}

function so_xfade() {
                var _self = this;

	cOpacity = this.imgs[this.current].xOpacity;
	nIndex = this.imgs[this.current+1]?this.current+1:0;

	nOpacity = this.imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	this.imgs[nIndex].style.display = "block";
	this.imgs[this.current].xOpacity = cOpacity;
	this.imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(this.imgs[this.current]); 
	setOpacity(this.imgs[nIndex]);
	
	if(cOpacity<=0) {
		this.imgs[this.current].style.display = "none";
		this.current = nIndex;
		setTimeout(function(){_self.so_xfade();},this.tempovisualizzazione);
	} else {
		setTimeout(function(){_self.so_xfade();},50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}

function xfade(divslide, tempovisualizzazione){
    this.divslide = new String(divslide);
    this.tempovisualizzazione = tempovisualizzazione;
    this.so_init =so_init;
    this.so_xfade = so_xfade;
    this.d=document;
    this.imgs = new Array();
    this.zInterval = null;
    this.current=parseInt(0);
    this.pause=false;
}

window.addEventListener?window.addEventListener("load",startslider,false):window.attachEvent("onload",startslider);

function startslider(){
   for (var kappa=0;kappa<sliders.length;kappa++){
      sliders[kappa].so_init();
    }
}
