/*
 * Modo de uso:
 *
 * Crear el objeto: var miobjeto = new imgTransition('nombrecapa','urlenlace')
 * donde nombrecapa es el ID del DIV que alojará las imágenes y
 * urlenlace
 */

function imgTransition(placeholder,width,height)
{
	this.name = placeholder
	this.obj = this.name + "Object"
	eval(this.obj + "=this")
	this.w = width
	this.h = height
	this.placeholder = new Object()
	this.espera = 3000
	this.intervalo = 3000
	this.continuar = 0						// A 0 se para cuando llega a la última imagen
	this.numImagenes = 0
	this.imagenes = new Array()
	this.enlacesImagenes = new Array()
	this.actImagen = 0
	this.sigImagen = 1
	this.enlace = new Object()
	this.img = new Object()
}

function initImgTransition()
{
	this.placeholder = document.getElementById(this.name)
	this.placeholder.width = this.w
	this.placeholder.height = this.h

	this.enlace = document.createElement("A")
	this.enlace.href = this.enlacesImagenes[0]
	this.placeholder.appendChild(this.enlace)

	this.img = this.enlace.appendChild(this.imagenes[0].cloneNode(0))
	this.img.width = this.w
	this.img.height = this.h
	if (is.ie) this.img.style.filter = "progid:DXImageTransform.Microsoft.Pixelate(MaxSquare=50,Duration=1,Enabled=false)"

	setTimeout(this.obj+".cambia()",this.espera)
}

function addImage(imgsrc,imgenlace)
{
	this.imagenes[this.numImagenes] = new Image()
	this.imagenes[this.numImagenes].src = imgsrc
	this.imagenes[this.numImagenes].style.border = 0
	if (imgenlace) 
		this.enlacesImagenes[this.numImagenes] = imgenlace 
	else
		this.enlacesImagenes[this.numImagenes] = "#"
	this.numImagenes++
}

function cambia()
{
	this.img.width = this.w
	this.img.height = this.h

	this.actImagen = this.sigImagen
	this.sigImagen = (this.sigImagen + 1) % this.numImagenes

	if (is.ie) this.img.filters.item(0).apply()
	this.img.src = this.imagenes[this.actImagen].src
	this.enlace.href = this.enlacesImagenes[this.actImagen]
	if (is.ie) this.img.filters.item(0).play()


	// Cuando hayamos dado una vuelta completa a las imágenes decidimos
	// si continuamos o no
	if (this.sigImagen == 0 && this.noparar == 0)
		return true; 

	setTimeout(this.obj+".cambia()",this.intervalo)
}

imgTransition.prototype.init = initImgTransition
imgTransition.prototype.addImage = addImage
imgTransition.prototype.cambia = cambia

function BrowserCheck() {
        var b = navigator.appName
        if (b=="Netscape") this.b = "ns"
        else if (b=="Microsoft Internet Explorer"||b=="Opera") this.b = "ie"
        else this.b = b
        this.version = navigator.appVersion
        this.v = parseInt(this.version)
        this.ns = (this.b=="ns" && this.v>=4)
        this.ns4 = (this.b=="ns" && this.v==4)
        this.ns5 = (this.b=="ns" && this.v==5)
        this.ie = (this.b=="ie" && this.v>=4)
        this.ie4 = (this.version.indexOf('MSIE 4')>0)
        this.ie5 = (this.version.indexOf('MSIE 5')>0)
        this.min = (this.ns||this.ie)
}
is = new BrowserCheck()
