var oAnimaHome=null
function animahome(a,b,c) {
	oAnimaHome=new cls_animazione(oObjMng.length,a,b,c)
	oObjMng[oObjMng.length]=oAnimaHome
}

function animaHomeLoadDone(m,x,n,nfo) {
	if (m) {
		var vt=$t(x,"GLS")
		if (vt.length!=0) {
			var v=$t(vt[0],"GL")
			var vv=[]
			for(var i=0;i<v.length;i++) {
				vv[i]=v[i].getAttribute("uid")	
			}
			oAnimaHome.postRead(vv)
		}
	}
}


function cls_animazione(obIndx,inBase,inSrc,inStop,idExt,idInt) {
	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.opa=100
	this.multiloop=true
	this.pr=10
	this.images=new Array()
	this.vcimg=inSrc
	this.oInt=null
	this.oExt=null
	this.clock=0
	this.idIntName=(idInt==undefined)?"anima1":idInt
	this.idExtName=(idExt==undefined)?"anima":idExt
	this.postInit=function postInit() {
		if (this.vcimg.length==0) {
			callAction(new Array("P",animaHomeLoadDone,"/_interno/getHome.php",""))
		} else {
			this.postInit2()
		}
	}
	this.postRead=function postRead(v) {
		this.vcimg=v
		this.postInit2()
	}

	this.postInit2=function postInit2() {
		this.maximg=this.vcimg.length-1
		if (this.maximg>=0) {
			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
			}
			this.oInt=$(this.idIntName)
			if (this.oInt) {this.oInt.style.backgroundImage="url("+this.base+this.vcimg[0]+this.ext+")"}
			this.oExt=$(this.idExtName)
			if (this.oExt) {
				if (this.maximg>0) {this.oExt.style.backgroundImage="url("+this.base+this.vcimg[1]+this.ext+")"}
			}
			if (this.oExt&&this.oInt&&this.maximg>0) {this.vcimg=null;this.clock=setTimeout("oObjMng["+this.obIndex+"].prerun()",10)}
		}
	}
	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("oObjMng["+this.obIndex+"].run()",nt)
		} else {
			this.pr+=10
			this.clock=setTimeout("oObjMng["+this.obIndex+"].prerun()",10)
		}
	}
	this.run=function run() {
		this.opa--
		
		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("oObjMng["+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("oObjMng["+this.obIndex+"].run()",this.stopTime)}
				}
			}
		} else {
			this.clock=setTimeout("oObjMng["+this.obIndex+"].run()",this.runTime)
		}	
	}
	this.unload=function unload() {
		clearTimeout(this.clock)
		this.oInt=null
		this.oExt=null
		this.images=null
	}
}
