

function Acordion(params) {

	this.elementos = new Array();
	
	for ( var i = 0 ; i < params.length; i++) {
		
		this.elementos.push( {
			indice: i,
			layer : document.getElementById(params[i])
		});
		
	}
	
}
Acordion.prototype.iniciar = function(){

	for ( var i = 0; i < this.elementos.length ; i++) {
		
		if (this.elementos[i].layer.getAttribute("indice") == "0") {
			var thisObj = this;
			this.elementos[i].layer.setAttribute ( "indice", i);
			this.elementos[i].layer.onclick = function(){ 
				thisObj.mostrar(Number(this.getAttribute("indice"))); 
			};
		}
		else
		{
			this.elementos[i].layer.style.display = 'none';
		}
		
	}
};


Acordion.prototype.mostrar = function(indice,fijo) {

	if (!fijo) var fijo = 0;
	
	for ( var i = 0; i < this.elementos.length ; i++){
		if (i%2!=0 && i != indice+1){
			this.elementos[i].layer.style.display = 'none';
		}
		else{
			
			var ch = this.elementos[i].layer.getElementsByTagName("img");
			
			var encontrado = false;
			var j =0;
			
			while (!encontrado && j < ch.length) {
				if (ch[j].getAttribute("id") == "iconoMenu"){
					ch[j].setAttribute("src", 'img/arrow-down.png');
					encontrado = true;
				}
				j++;
			}
			
		}
		
	}
	
	if (indice + 1 < this.elementos.length){
	
		if (this.elementos[indice+1].layer.style.display == 'none' || fijo == 1) {
			this.elementos[indice+1].layer.style.display = 'block';
			
			//cambiar el icono
			var ch = this.elementos[indice].layer.getElementsByTagName("img");
			
			var encontrado = false;
			var i =0;
			
			while (!encontrado && i < ch.length) {
				if (ch[i].getAttribute("id") == "iconoMenu"){
					ch[i].setAttribute("src", 'img/arrow-right.png');
					encontrado = true;
				}
				i++;
			}
		}
		else{
			this.elementos[indice+1].layer.style.display = 'none';
			
			//cambiar el icono
			var ch = this.elementos[indice].layer.getElementsByTagName("img");
			
			var encontrado = false;
			var i =0;
			
			while (!encontrado && i < ch.length) {
				if (ch[i].getAttribute("id") == "iconoMenu"){
					ch[i].setAttribute("src", 'img/arrow-down.png');
					encontrado = true;
				}
				i++;
			}
		}
		
		
		
		//(this.elementos[indice+1].layer.style.display == 'block')?'none':'block';
		try {
			ajustarSizeResultados(this.elementos[indice+1].layer.style.height);
		}
		catch(e) {
		}
	}

};


