// ===================================================================================
// Funciones JavaScript para pestañas
// ===================================================================================

// Constructor
function Pest(id, idPest, idCapasPest, nombreEstilos)
{
	this.id = id;
	// Array con los ID de las pestañas
	this.idPest = idPest;
	// Array con los ID de las capas asociadas a pestañas
	this.idCapasPest = idCapasPest;
	// Array con los nombres de los estilos
	this.nombreEstilos = nombreEstilos;
}

// Indices de los nombres de estilos (propiedades de clase)
Pest.ESTILO_ACT_IZQ = 0;
Pest.ESTILO_ACT_CEN = 1;
Pest.ESTILO_ACT_DER = 2;
Pest.ESTILO_DES_IZQ = 3;
Pest.ESTILO_DES_CEN = 4;
Pest.ESTILO_DES_DER = 5;

Pest.prototype.activarPest = function(id)
{
	for (var i = 0; i < this.idPest.length; ++i) {
		// Identificadores de las pestañas: 'pest-' + id; 
		// Separador izquierdo: 'pest-izq-' + id (primera pest.); 'pest-' + this.idPest[i-1] + '-' + id (resto)
		// Separador derecho: 'pest-' + id + '-der' (última pest.); 'pest-' + id + '-' + this.idPest[i+1] (resto)
		var capa_izq = document.getElementById('pest-izq-' + this.idPest[i]);
		var capa = document.getElementById('pest-' + this.idPest[i]);
		var capa_der = document.getElementById('pest-' + this.idPest[i] + '-der');
		
		capa_izq.className = (this.idPest[i] == id ? this.nombreEstilos[Pest.ESTILO_ACT_IZQ] : this.nombreEstilos[Pest.ESTILO_DES_IZQ]);
		capa.className = (this.idPest[i] == id ? this.nombreEstilos[Pest.ESTILO_ACT_CEN] : this.nombreEstilos[Pest.ESTILO_DES_CEN]);
		capa_der.className = (this.idPest[i] == id ? this.nombreEstilos[Pest.ESTILO_ACT_DER] : this.nombreEstilos[Pest.ESTILO_DES_DER]);
	}
}

Pest.prototype.activarCapaPest = function(id)
{
	for (var i = 0; i < this.idCapasPest.length; ++i) {
		var capa = document.getElementById(this.idCapasPest[i]);
		if (capa) {
			if (this.idCapasPest[i] == id) {
				capa.style.visibility = 'visible';
			} else {
				capa.style.visibility = 'hidden';
			}
		}
	}
}
