// JavaScript Document

function amagaElement(id,tipus){

	var ele=document.getElementById(id);
	try{
		ele.style.visibility='hidden';
		if(!tipus){
			ele.style.display='none';
		}else{
			ele.style.display=tipus;
		}
	}catch(e){ 
	//	alert(e);
	}
}

function mostraElement(id,tipus){

	var ele=document.getElementById(id);
	try{
		ele.style.visibility='visible';
		if(!tipus){
			ele.style.display='block';
		}else{
			ele.style.display=tipus;
		}
	}catch(e){
	//	alert(e);
	}
}


function ancoraElement(id_ancora, id_element, offset_x, offset_y, align_right){
	
	ancora=document.getElementById(id_ancora);
	element=document.getElementById(id_element);
	
	  var y = 0;
	  var x = 0;

	if(!ancora.style.left || !ancora.style.top){
	  while (ancora.offsetParent) {
		x += ancora.offsetLeft;
		y += ancora.offsetTop;
		ancora = ancora.offsetParent;
	 }	
	}else{
		x=ancora.style.left;
		y=ancora.style.top;
	}
	
	if(align_right){
	//	alert("ancora offset = "+ancora.scrollWidth);
//		alert("element offset = "+element.scrollWidth);
		x-=element.scrollWidth;
	}

	element.style.left=(x+offset_x)+"px";
	element.style.top=(y+offset_y)+"px";
	
}

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.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.pestanyes_on.mostraSolPerIndex(index);
		this.pestanyes_off.amagaSolPerIndex(index);		
		this.continguts.mostraSolPerIndex(index);
	}
	
}
