/*
	DynAPI Distribution.
	Veiss : Transition Class.

	The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/

// Traducción de textos

switch(idioma) {
case 1: // Español
	idioma_cargando = 'cargando...';
	break;
case 2: // Inglés
	idioma_cargando = 'loading...';
	break;
case 3: // Francés
	idioma_cargando = 'chargement...';
	break;
case 4: // Portugués
	idioma_cargando = 'loading...';
	break;
}

Transition = function(l, t, w, h, dl, dt, src, csrc, bg, brd, vis) {
	this.id = 'Transition' + Transition.Count++;
	Transition.all[this.id] = this;

	this.l = l;
	this.t = t;
	this.w = w;
	this.h = h;
	this.mw = Math.round(0.5 * w);
	this.mh = Math.round(0.5 * h);

	this.dl = dl;
	this.cdl = 0;

	this.dt = dt;
	this.cdt = 0;

	this.time = 25;
	this.lock = true;

	this.lyr = new DynLayer(null, l, t, w, h, bg, false);
	this.lyr.setZIndex(1);
	this.blyr = new DynLayer(null, l - 1, t - 1, w + 2, h + 2, brd, false);
	this.blyr.setZIndex(1);

	// DynAPI.document.addChild(this.blyr);
	// DynAPI.document.addChild(this.lyr);

	DynObject.all.fotosDIV.addChild(this.blyr);
	DynObject.all.fotosDIV.addChild(this.lyr);

	this.setVisible(vis);

	// Crear la capa del "cargando..."

	this.loadinglyr = new DynLayer(null, (w - 100) /2, (h - 20) / 2, 100, 20);
	this.loadinglyr.setHTML('<table cellspacing="0" cellpadding="0" border="0" width="100"><tr><td align="center" class="texto">' + idioma_cargando + '</td></table>');
	this.lyr.addChild(this.loadinglyr);

	// Crear la capa de la foto

	this.photolyr = new DynLayer(null, 0, 0, w, h);
	this.photolyr.setHTML('<a href="javascript:Transition.all.' + this.id + '.close()" onfocus="blur()"><img name="' + this.id + 'FOT" src="' + images +'/pixel.gif" width="' + w +'" height="' + h + '" border="0"></a>');
	this.lyr.addChild(this.photolyr);

	// Crear la capa del botón de cerrar

	this.closelyr = new DynLayer(null, 6, 6, 53, 21);
	this.closelyr.setHTML('<a href="javascript:Transition.all.' + this.id + '.close()" onfocus="blur()"><img name="' + this.id + 'BOT" src="' + images +'/pixel.gif" width="53" height="21" border="0"></a>');
	this.lyr.addChild(this.closelyr);

	// Cargar las imágenes

	this.photolyr.img = this.photolyr.doc.images[this.id + 'FOT'];
	this.photolyr.imgorig = new Image();
	this.photolyr.imgorig.src = src;

	this.closelyr.img = this.closelyr.doc.images[this.id + 'BOT'];
	this.closelyr.imgorig = new Image();
	this.closelyr.imgorig.src = csrc;
	this.closelyr.imgover = new Image();
	this.closelyr.imgover.src = this.closelyr.imgorig.src.replace(/(.gif|.jpg|.png)$/, '_over$1');

	this.photolyr.img.src = this.photolyr.imgorig.src;
	this.closelyr.img.src = this.closelyr.imgorig.src;

	// Asignar los eventos del rollover

	this.closelyr.listener = new EventListener();
	this.closelyr.listener.onmouseover = function(ev) {
		var obj = ev.getSource();
		obj.img.src = obj.imgover.src;
	};
	this.closelyr.listener.onmouseout = function(ev) {
		var obj = ev.getSource();
		obj.img.src = obj.imgorig.src;
	};
	this.closelyr.addEventListener(this.closelyr.listener);

	this.lock = false;
};
Transition.Count = 0;
Transition.all = [];
Transition.prototype.setVisible = function(vis) {
	if(vis) {
		this.blyr.setClip([0, this.w + 2, this.h + 2, 0]);
		this.lyr.setClip([0, this.w, this.h, 0]);
	} else {
		this.blyr.setClip([this.mh - 1 + this.dt, this.mw - 1 + this.dl, this.mh + 1 + this.dt, this.mw + 1 + this.dl]);
		this.lyr.setClip([this.mh, this.mw, this.mh, this.mw]);
	}
	this.lyr.setVisible(vis);
	this.blyr.setVisible(vis);
};
Transition.prototype.open = function() {
	if(!this.lock) {
		this.lock = true;
		this.cdl = this.dl;
		this.cdt = this.dt;
		this.lyr.setVisible(true);
		this.blyr.setVisible(true);

		this.photolyr.img.src = this.photolyr.imgorig.src;
		this.closelyr.img.src = this.closelyr.imgorig.src;

		setTimeout('Transition.all.' + this.id + '.opening(0, 0)', this.time);
	}
};
Transition.prototype.opening = function(w, h)
{
	if(w < this.mw || h < this.mh) {
		var dw = this.mw - w;
		if(dw < 0) dw = 0;

		var dh = this.mh - h;
		if(dh < 0) dh = 0;

		this.blyr.setClip([dh + this.cdt, this.w - dw + 2 + this.cdl, this.h - dh + 2 + this.cdt, dw + this.cdl]);
		this.lyr.setClip([dh + this.cdt, this.w - dw + this.cdl, this.h - dh + this.cdt, dw + this.cdl]);

		w += Math.ceil(0.125 * dw);
		h += Math.ceil(0.125 * dh);

		if(this.dl) this.cdl = Math.floor((dw / this.mw) * this.dl);
		if(this.dt) this.cdt = Math.floor((dh / this.mh) * this.dt);

		setTimeout('Transition.all.' + this.id + '.opening(' + w + ', ' + h + ')', this.time);
	} else {
		this.setVisible(true);
		this.lock = false;
	}
};
Transition.prototype.close = function() {
	if(!this.lock) {
		this.lock = true;
		this.cdl = 0;
		this.cdt = 0;
		setTimeout('Transition.all.' + this.id + '.closing(0, 0)', this.time);
	}
};
Transition.prototype.closing = function(w, h)
{
	if(w < this.mw || h < this.mh) {
		var dw = this.mw - w;
		if(dw < 0) dw = 0;

		var dh = this.mh - h;
		if(dh < 0) dh = 0;

		this.blyr.setClip([h + this.cdt, this.w - w + 2 + this.cdl, this.h - h + 2 + this.cdt, w + this.cdl]);
		this.lyr.setClip([h + this.cdt, this.w - w + this.cdl, this.h - h + this.cdt, w + this.cdl]);

		w += Math.ceil(0.125 * dw);
		h += Math.ceil(0.125 * dh);

		if(this.dl) this.cdl = Math.floor((1 - (dw / this.mw)) * this.dl);
		if(this.dt) this.cdt = Math.floor((1 - (dh / this.mh)) * this.dt);

		setTimeout('Transition.all.' + this.id + '.closing(' + w + ', ' + h + ')', this.time);
	} else {
		this.setVisible(false);
		this.lock = false;
	}
};
