/*****************************************************************************/
/*                               (c) 2009 GIGA                               */
/*                        JAVASCRIPT GENERAL DE LA WEB                       */
/*****************************************************************************/

// CUENTA ATRAS
var CuentaAtras = Class.create();
CuentaAtras.prototype = {
	initialize: function (variable, tiempo, destino) {
		this.variable 	= variable;
		this.tiempo 	= tiempo;
		this.destino 	= destino;
	},

	calcular: function () {
		var dias, horas, minutos, segundos;

		segundos = this.tiempo % 60;
		minutos = (this.tiempo % 3600 - segundos) / 60;
		horas = (this.tiempo % (24 * 3600) - minutos * 60 - segundos) / 3600;
		dias = (this.tiempo - this.tiempo % (24 * 3600)) / (24 * 3600);

		return { dias: dias, horas: horas, minutos: minutos, segundos: segundos };
	},

	genVisible: function (entrada) {
		return entrada.dias+' días y '+(entrada.horas<10?'0':'')+entrada.horas+':'+(entrada.minutos<10?'0':'')+entrada.minutos+':'+(entrada.segundos<10?'0':'')+entrada.segundos;
	},

	start: function () {
		this.transicion();
	},

	transicion: function () {
		if (this.tiempo > 0) {
			setTimeout(this.variable+'.transicion()',1000);
			$(this.destino).update(this.genVisible(this.calcular()));
			this.tiempo--;
		}
	}
};
