// JavaScript Document
var oObjs_fader=new Array()

function oObjs_fader_unload() {
	for (var i=0;i<oObjs_fader.length;i++) {
		if (oObjs_fader[i].unload) {oObjs_fader[i].unload()}
	}
}
addUnLoader(oObjs_fader_unload)

function build_crossfade(a,b,c,d,e) {
	oObjs_fader[oObjs_fader.length]=new cls_crossfade(oObjs_fader.length,a,b,c,d,e)

}
function cls_crossfade(obIndx,inObj,inBase,inSrc,inHeight,inStop) {
	this.obIndex=obIndx
	this.cimg=0
	this.base=inBase
	this.ext=".jpg"
	this.maximg=inSrc.length
	this.runTime=50
	this.stopTime=(inStop==undefined)?2000:inStop
	this.baseHeight=(inHeight==undefined)?"":(inHeight+"")
	this.opa=100
	this.multiloop=true
	this.pr=10
	this.images=new Array()
	this.vcimg=inSrc
	this.oExt=$b("div")
	this.oExt.className="crossfade"
	inObj.appendChild(this.oExt)
	this.oInt=$b("div")
	this.oInt.className="crossfade"
	this.oExt.appendChild(this.oInt)
	this.clock=0
	
	
	this.postInit2=function postInit2() {
		this.maximg=this.vcimg.length-1
		for (var i=0;i<=this.maximg;i++) {
			var ci=new Image()
			ci.src=this.base+this.vcimg[i]+this.ext
			this.images[i]=ci
		}
		if (this.oInt) {this.oInt.style.backgroundImage="url("+this.base+this.vcimg[0]+this.ext+")";if (this.baseHeight!="") {this.oInt.style.height=this.baseHeight+"px"}}
		if (this.oExt) {this.oExt.style.backgroundImage="url("+this.base+this.vcimg[1]+this.ext+")"}
		if (this.oExt&&this.oInt) {this.vcimg=null;this.clock=setTimeout("oObjs_fader["+this.obIndex+"].prerun()",10)}
	}
	this.postInit2()

	this.prerun=function prerun() {
		var ok=true
		for(var i=0;i<this.images.length;i++) {
			if (!this.images[i].complete) {ok=false}
		}
		if(ok) {
			var nt=this.stopTime-this.pr
			if (nt<10) {nt=10}
			this.clock=setTimeout("oObjs_fader["+this.obIndex+"].run()",nt)
		} else {
			this.pr+=10
			this.clock=setTimeout("oObjs_fader["+this.obIndex+"].prerun()",10)
		}
	}

	this.run=function run() {
		this.opa--
		this.opa--
		if (this.opa<1) {this.opa=1}
		this.oInt.style.opacity=(this.opa/100);this.oInt.style.filter="alpha(opacity="+this.opa+")"
		if (this.opa==1) {
			if (this.multiloop) {
				this.cimg=(this.cimg<this.maximg)?(this.cimg+1):0
				var nstagione=(this.cimg<this.maximg)?(this.cimg+1):0
				this.oInt.style.backgroundImage="url("+this.images[this.cimg].src+")"
				this.opa=99
				this.oInt.style.opacity=(this.opa/100)
				this.oInt.style.filter="alpha(opacity="+this.opa+")"
				this.oExt.style.backgroundImage="url("+this.images[nstagione].src+")"
				this.clock=setTimeout("oObjs_fader["+this.obIndex+"].run()",this.stopTime)
			} else {
				if (this.cimg<this.maximg) {
					this.cimg++
					this.oInt.style.backgroundImage="url("+this.images[this.cimg].src+")"
					this.opa=99
					this.oInt.style.opacity=(this.opa/100)
					this.oInt.style.filter="alpha(opacity="+this.opa+")"
					this.oExt.style.backgroundImage="url("+this.images[this.cimg].src+")"
					if (this.cimg<this.maximg) {this.clock=setTimeout("oObjs_fader["+this.obIndex+"].run()",this.stopTime)}
				}
			}
		} else {
			this.clock=setTimeout("oObjs_fader["+this.obIndex+"].run()",this.runTime)
		}
	}
	
	this.ricarica=function ricarica(inBase,inSrc) {
		clearTimeout(this.clock)
		this.base=inBase
		this.maximg=inSrc.length
		this.vcimg=inSrc
		this.opa=100
		this.pr=10
		this.cimg=0
		this.oInt.style.opacity=(this.opa/100);this.oInt.style.filter="alpha(opacity="+this.opa+")"
		this.postInit2()
	}
	
	this.unload=function unload() {
		clearTimeout(this.clock)
		this.oInt=null
		this.oExt=null
		this.images=null
	}
}
