// JavaScript Document

function amagaElement(id){

	var ele=document.getElementById(id);
	try{
		ele.style.visibility='hidden';
		ele.style.display='none';
	}catch(e){}
}

function mostraElement(id){

	var ele=document.getElementById(id);
	try{
		ele.style.visibility='visible';
		ele.style.display='block';
	}catch(e){}
}

function grupElements(){
	this.elements = new Array();
	
	this.nouElement = function nouElement(id){
		this.elements[this.elements.length]=id;	
		return this.elements.length-1;
	}
	
	this.amagaTots = function amagaTots(){
		var i;
		for(i=0;i<this.elements.length;i++){
			amagaElement(this.elements[i]);	
		}
	}

	this.mostraTots = function mostraTots(){
		var i;
		for(i=0;i<this.elements.length;i++){
			mostraElement(this.elements[i]);	
		}
	}

	this.mostraSolPerId = function mostraSolPerId(id){
		this.amagaTots();
		mostraElement(id);
	}
	
	this.mostraSolPerIndex = function mostraSolPerIndex(index){
		this.amagaTots();
		mostraElement(this.elements[index]);
	}
	
	this.amagaSolPerId = function amagaSolPerId(id){
		this.mostraTots();
		amagaElement(id);
	}
	
	this.amagaSolPerIndex = function amagaSolPerIndex(index){
		this.mostraTots();
		amagaElement(this.elements[index]);
	}	
	
	this.getNElements = function getNElements(){
		return this.elements.length;	
	}

}



function pestanyesContinguts(){
	this.i=0;
	this.pestanyes_on=new grupElements();
	this.pestanyes_off=new grupElements();
	this.continguts=new grupElements();
	
	this.novaSeccio = function novaSeccio(id_pestanya_on, id_pestanya_off, id_contingut){
		this.pestanyes_on.nouElement(id_pestanya_on);
		this.pestanyes_off.nouElement(id_pestanya_off);		
		this.continguts.nouElement(id_contingut);
		
		return this.pestanyes_on.getNElements()-1;
	}
	
	this.selecciona = function selecciona(index){
		this.i=index;
		this.pestanyes_on.mostraSolPerIndex(index);
		this.pestanyes_off.amagaSolPerIndex(index);		
		this.continguts.mostraSolPerIndex(index);
	}
	this.avanca = function avanca(){
		if(this.i<this.pestanyes_on.getNElements()-1){
			this.i++;
			this.pestanyes_on.mostraSolPerIndex(this.i);
			this.pestanyes_off.amagaSolPerIndex(this.i);		
			this.continguts.mostraSolPerIndex(this.i);
		}	
	}
	this.retrocedeix = function retrocedeix(){
		if(this.i>0){
			this.i--;
			this.pestanyes_on.mostraSolPerIndex(this.i);
			this.pestanyes_off.amagaSolPerIndex(this.i);		
			this.continguts.mostraSolPerIndex(this.i);
		}
	}
	this.pintapag = function pintapag(){
		document.getElementById("pintapag").innerHTML=" " + (this.i+1) + "/" + this.pestanyes_on.getNElements() + " "; 
	}
	
	this.amaga = function amaga(){
		this.pestanyes_on.amagaTots();
		this.pestanyes_off.amagaTots();
		this.continguts.amagaTots();
	}
	this.mostratots=function mostratots(){
		this.pestanyes_off.mostraTots();
	}
	this.mostra = function mostra(){
		this.selecciona(this.i);
	}
}
