/****************************************************************************************************
		JJBM, 14/05/2004, Interpolador

		Clase Interpolador

			Interpolador( a, b )

				a	valor inicial
				b	valor final

			t( t )

				t	valor normalizado [0, 1]

*/
	function Interpolador_t( t ) {
		return this.a * ( 1.0 - t ) + this.b * t
	}
	function Interpolador( a, b ) {
		this.a = a
		this.b = b
		this.t = Interpolador_t
	}



/****************************************************************************************************
	JJBM, 14/05/2004, Banner de tipo fade.

	Clase	fadeBanner

		fadeBanner( NombreClase, Imagen, Xi, Xf, Yi, Yf, Wi, Wf, Hi, Hf, Ai, Af, NPasos, Milisegundos, OnTerminar )

			NombreClase		el nombre de la variable que contiene la clase creada.
			Imagen			objeto imagen con la imagen a usar como base del fade.
			Xi				posición X inicial
			Xf				posición X final
			Yi				posición Y inicial
			Yf				posición Y final
			Wi				anchura inicial o indicador de usar dimensión proporcional <0
			Wf				anchura final
			Hi				altura o porcentaje de dimensión inicial
			Hf				altura o porcentaje de dimensión final
			Ai				alpha inicial
			Af				alpha final
			NPasos			número de pasos (eq. a frames) a generar en la animación
			Milisegundos	duración total de la animación en milisegundos
			OnTerminar		null o función a la que llamará el fade al terminar

		Iniciar()

			inicia la animación con los parámetros pasados

		Ocultar()

			finaliza burscamente la animación

*/
	function fadeBanner_Paso() {
		with( this.Imagen.style ) {
			left		= this.X.t(this.t) + "px"
			top		= this.Y.t(this.t) + "px"
			if( this.W.a < 0.0 ) {
				width	= Math.round( ( this.Copia.width  * this.H.t(this.t) ) * 0.01 ) + "px"
				height	= Math.round( ( this.Copia.height * this.H.t(this.t) ) * 0.01 ) + "px"
			} else {
				width	= this.W.t(this.t) + "px"
				height	= this.H.t(this.t) + "px"
			}
			filter		= "FILTER: Alpha(Opacity=" + Math.round( this.A.t(this.t) ) + ")"

			var o = parseInt( Math.round( this.A.t(this.t) ) )
			opacity		= "0." + ( o < 10 ? '0' : '' ) + o
			
			if( ( this.t += this.it ) > 1.0 || this.Estado == 0 ) {
				this.Estado = 0
				clearInterval( this.hT )
				if( this.OnTerminar != null ) this.OnTerminar()
			}
		}
	}
	function fadeBanner_Iniciar() {
		if( this.Estado == 0 ) {
			this.Copia	= document.createElement("IMG")
			this.Copia.src	= this.Imagen.src
			this.Estado	= 1
			this.t		= 0.0
			this.it		= 1.0 / ( 1.0 * this.NPasos )
			this.hT		= setInterval( this.NombreClase + ".Paso()", this.Milisegundos * this.it )
			this.Paso()
			this.Imagen.style.display = 'inline'
		}
	}
	function fadeBanner_Ocultar() {
		with( this.Imagen.style ) {
			this.Estado	= left	= top = 0
			width	= height	= 1
			filter		= "FILTER: Alpha(Opacity=0)"
			opacity = "1.0"
		}
	}
	function fadeBanner( NombreClase, Imagen, Xi, Xf, Yi, Yf, Wi, Wf, Hi, Hf, Ai, Af, NPasos, Milisegundos, OnTerminar ) {
		this.NombreClase		= NombreClase
		this.Imagen				= Imagen
		this.X	= new Interpolador( Xi, Xf );	this.Y	= new Interpolador( Yi, Yf )
		this.W	= new Interpolador( Wi, Wf );	this.H	= new Interpolador( Hi, Hf )
		this.A	= new Interpolador( Ai, Af )
		this.NPasos				= NPasos
		this.Milisegundos		= Milisegundos
		this.Estado				= 0
		this.Paso				= fadeBanner_Paso
		this.Iniciar			= fadeBanner_Iniciar
		this.OnTerminar			= OnTerminar
		this.Ocultar			= fadeBanner_Ocultar
	}


/***************************************************************************************************
	JJBM, 14/05/2004, fade completo

	Clase	fadeCompleto

		fadeCompleto( NombreClase, Imagen, Xi, Xf, Yi, Yf, Wi, Wf, Hi, Hf, tOpaco, NPasos, Milisegundos, OnTerminar )

			tOpaco	tiempo del tramo central en la que la imagen está totalmente opaca
*/
	function fadeCompleto_PasoA() { this.Padre.B.Iniciar(); this.Padre.Q = this.Padre.B }
	function fadeCompleto_PasoB() { this.Padre.C.Iniciar(); this.Padre.Q = this.Padre.C }
	function fadeCompleto_PasoC() {
		this.Padre.Ocultar()
		if( this.Padre.OnTerminar != null ) this.Padre.OnTerminar()
	}
	function fadeCompleto_Ocultar() { this.Q.Ocultar() }
	function fadeCompleto_Iniciar() {
		this.A.OnTerminar = eval( this.NombreClase + ".PasoA" )
		this.B.OnTerminar = eval( this.NombreClase + ".PasoB" )
		this.C.OnTerminar = eval( this.NombreClase + ".PasoC" )
		this.A.Iniciar()
	}
	function fadeCompleto( N, I, Xi, Xf, Yi, Yf, Wi, Wf, Hi, Hf, tOpaco, NP, TT, OnTerminar ) {
		var	u = 0.5 - tOpaco / ( TT * 2.0 ),
			v = 1.0 - u,
			q = TT * ( v - u ),
			r = NP * u,
			s = TT * u,
			t = NP * ( v - u )
		var x = new Interpolador( Xi, Xf )
		var y = new Interpolador( Yi, Yf )
		var w = new Interpolador( Wi, Wf )
		var h = new Interpolador( Hi, Hf )
		this.NombreClase = N
		this.PasoA = fadeCompleto_PasoA
		this.PasoB = fadeCompleto_PasoB
		this.PasoC = fadeCompleto_PasoC
		this.Iniciar = fadeCompleto_Iniciar
		this.Ocultar = fadeCompleto_Ocultar
		this.OnTerminar = OnTerminar
		this.A=new fadeBanner(N+".A",I,x.t(0),x.t(u),y.t(0),y.t(u),w.t(0),w.t(u),h.t(0),h.t(u),  0,100,r,s,null);
		this.B=new fadeBanner(N+".B",I,x.t(u),x.t(v),y.t(u),y.t(v),w.t(u),w.t(v),h.t(u),h.t(v),100,100,t,q,null);
		this.C=new fadeBanner(N+".C",I,x.t(v),x.t(1),y.t(v),y.t(1),w.t(v),w.t(1),h.t(v),h.t(1),100,  0,r,s,null);
		this.A.Padre = this
		this.B.Padre = this
		this.C.Padre = this
		this.Q=this.A
	}


/********************************************************************************
	JJBM, 14/05/2004, fade completo en tira

	Clase fadeCompletoTirada

		fadeCompletoTirada( NombreClase, Imagen, Imagenes, Xi, Xf, Yi, Yf, Wi, Wf, Hi, Hf, tOpaco, NPasos, Milisegundos, OnTerminar )

			Imagenes	un vector con orígenes (url) de imágenes a tirar, debe tener inicializada una variable
						llamada contador a 0.
*/

	function fadeCompletoTirada_Paso_k(o) {
		var q = o.Vector.contador++
		if( q < o.Vector.length ) {
			o.Imagen.src = o.Vector[q]
			o.fade.Iniciar()
		}
	}
	function fadeCompletoTirada_Paso() {
		fadeCompletoTirada_Paso_k( this.Padre )
	}
	function fadeCompletoTirada_Iniciar() {
		this.fade.OnTerminar = eval( this.NombreClase + ".Paso" )
		fadeCompletoTirada_Paso_k( this )
	}
	function fadeCompletoTirada( NombreClase, Imagen, Imagenes, Xi, Xf, Yi, Yf, Wi, Wf, Hi, Hf, tOpaco, NPasos, Milisegundos, OnTerminar ) {
		this.Imagen			= Imagen
		this.Vector			= Imagenes
		this.Paso			= fadeCompletoTirada_Paso
		this.OnTerminar		= OnTerminar
		this.NombreClase	= NombreClase
		this.Iniciar		= fadeCompletoTirada_Iniciar
		this.fade			= new fadeCompleto( NombreClase + ".fade", Imagen, Xi, Xf, Yi, Yf, Wi, Wf, Hi, Hf, tOpaco, NPasos, Milisegundos, null )
		this.fade.Padre		= this
	}


/********************************************************************************
	JJBM, 18/05/2004, fade en cortina

*/


	function fadeCortina_Paso() {
		var w, h
		document.all[ this.Frame.name ].width	= w = this.W.t(this.t)
		document.all[ this.Frame.name ].height	= h = this.H.t(this.t)
		this.Capa.style.left	= this.Xo + Math.floor( this.X.t(this.t) * w )
		this.Capa.style.top	= this.Yo + Math.floor( this.Y.t(this.t) * h )
		this.Capa.style.filter = "Alpha(Opacity=" + Math.round( this.A.t(this.t) ) + ")"
		switch( this.OrientacionH ) {
		case 0: this.Frame.document.all.Capa.style.left = ( w - this.Wc ) >> 1; break
		case 1: this.Frame.document.all.Capa.style.left = 0; break
		case 2: this.Frame.document.all.Capa.style.left = w - this.Wc; break
		}
		switch( this.OrientacionV ) {
		case 0: this.Frame.document.all.Capa.style.top = ( h - this.Hc ) >> 1; break
		case 1: this.Frame.document.all.Capa.style.top = 0; break
		case 2: this.Frame.document.all.Capa.style.top = h - this.Hc; break
		}
		if( ( this.t += this.it ) > 1.0 || this.Estado == 0 ) {
			this.Estado = 0
			clearInterval( this.hT )
			if( this.OnTerminar != null ) this.OnTerminar()
		}
	}
	function fadeCortina_Iniciar() {
		if( this.Estado == 0 ) {
			this.Capa.style.top		= this.Yo
			this.Capa.style.left	= this.Xo
			this.Frame.document.body.style.marginTop		= 0
			this.Frame.document.body.style.marginBottom		= 0
			this.Frame.document.body.style.marginLeft		= 0
			this.Frame.document.body.style.marginRight		= 0
			if( this.W.a < 0 ) this.W.a = this.Frame.document.all.Tabla.offsetWidth
			if( this.W.b < 0 ) this.W.b = this.Frame.document.all.Tabla.offsetWidth
			if( this.H.a < 0 ) this.H.a = this.Frame.document.all.Tabla.offsetHeight
			if( this.H.b < 0 ) this.H.b = this.Frame.document.all.Tabla.offsetHeight
			this.Wc = this.Frame.document.all.Tabla.offsetWidth
			this.Hc = this.Frame.document.all.Tabla.offsetHeight
			document.all[ this.Frame.name ].width	= this.Wc
			document.all[ this.Frame.name ].height	= this.Hc
			this.Estado		= 1
			this.t			= 0.0
			this.it			= 1.0 / ( 1.0 * this.NPasos )
			this.Capa.style.display = "block"
			this.hT			= setInterval( this.Clase + ".Paso()", this.Milisegundos * this.it )
		}
	}
	function fadeCortina_Ocultar() {
		this.Capa.style.display	= "none"
		this.Estado		= 0
		clearInterval( this.hT )
	}
	function fadeCortina( NC,C,F,Xo,Yo,Xi,Xf,Yi,Yf,Wi,Wf,Hi,Hf,Ai,Af,Oh,Ov,NP,Msg,OnT ) {
		this.Clase			= NC
		this.Capa			= C
		this.Frame			= F
		this.Xo				= Xo
		this.Yo				= Yo
		this.X				= new Interpolador( Xi, Xf )
		this.Y				= new Interpolador( Yi, Yf )
		this.W				= new Interpolador( Wi, Wf )
		this.H				= new Interpolador( Hi, Hf )
		this.A				= new Interpolador( Ai, Af )
		this.OrientacionH	= Oh
		this.OrientacionV	= Ov
		this.NPasos			= NP
		this.Milisegundos	= Msg
		this.Estado			= 0
		this.Paso			= fadeCortina_Paso
		this.Iniciar		= fadeCortina_Iniciar
		this.Ocultar		= fadeCortina_Ocultar
		this.OnTerminar		= OnT
	}
/********************************************************************************
	JJBM, 18/05/2004, fade en cortina completo

*/


	function fadeCortinaCompleto_PasoA() { this.Padre.Crono = setTimeout( this.Padre.Clase + ".B.Iniciar()",  this.Padre.tEspera ); this.Padre.Q = this.Padre.B }
	function fadeCortinaCompleto_PasoB() {
		this.Padre.Ocultar()
		if( this.Padre.OnTerminar != null ) this.Padre.OnTerminar()
	}
	function fadeCortinaCompleto_Ocultar() { clearTimeout( this.Crono ); this.Q.Ocultar() }
	function fadeCortinaCompleto_Iniciar() {
		this.A.OnTerminar = eval( this.Clase + ".PasoA" )
		this.B.OnTerminar = eval( this.Clase + ".PasoB" )
		this.A.Iniciar()
	}
	function fadeCortinaCompleto( NC,C,F,Xo,Yo,Xi,Xf,Yi,Yf,Wi,Wf,Hi,Hf,Ai,Af,Oh,Ov,Tv,NP,Msg,OnT ) {
	// NC	- nombre de la clase
	// C	- nombre ID de la capa
	// F	- es el ID y NAME del iFrame
	// Xo	- posición X del "anchor" de la cortina
	// Yo	- posición Y del "anchor" de la cortina
	// Xi	- multiplicador de la anchura actual para el desplazamiento X
	// Xf	- multiplicador de la anchura actual para el desplazamiento X
	// Yi	- multiplicador de la anchura actual para el desplazamiento Y
	// Yf	- multiplicador de la anchura actual para el desplazamiento Y
	// Wi	- anchura inicial de la cortina
	// Wf	- anchura final de la cortina
	// Hi	- altura inicial de la cortina
	// Hf	- altura final de la cortina
	// Ai	- alfa inicial
	// Af	- alfa final
	// Oh	- orientación horizontal respecto el anchor ( 0 - centrado, 1 - izquierda, 2 - derecha )
	// Ov	- orientación vertical respecto el anchor ( 0 - centrado, 1 - arriba, 2 - abajo )
	// Tv	- tiempo de espera de visualización de la cortina
	// NP	- número de pasos
	// Msg	- tiempo total de la aparición == tt desaparición
	// OnT	- evento al terminar
		this.Clase	= NC
		this.tEspera	= Tv
		this.PasoA	= fadeCortinaCompleto_PasoA
		this.PasoB	= fadeCortinaCompleto_PasoB
		this.Iniciar = fadeCortinaCompleto_Iniciar
		this.Ocultar = fadeCortinaCompleto_Ocultar
		this.OnTerminar = OnT
		this.A=new fadeCortina(NC+".A",C,F,Xo,Yo,Xi,Xf,Yi,Yf,Wi,Wf,Hi,Hf,Ai,Af,Oh,Ov,NP,Msg,null);
		this.B=new fadeCortina(NC+".B",C,F,Xo,Yo,Xf,Xi,Yf,Yi,Wf,Wi,Hf,Hi,Af,Ai,Oh,Ov,NP,Msg,null);
		this.A.Padre = this
		this.B.Padre = this
		this.Q=this.A
	}
