function xControlMen(id,idKapa,estilos,tim){
	xCMObj= new xControlMen.create(id,idKapa,estilos,tim);
	eval('xCM'+id+'=xCMObj');
	return xCMObj;
}

xControlMen.create=function(id,idKapa,estilos,tim){
	this.arg=arguments;
	this.tiempo=0;
	this.actvFun=0;
	this.classElement=[];
	this.id='xCM'+id;

	for(var x=0;x<=this.arg[2].length;x++){
		this.classElement[x]=this.arg[2].split("/")[x];
	}
}

xControlMen.create.prototype.actvOpc=function(idTd,idHref,ev){
	var classHref=0;
	//farem un tractament especial per a la primera opcio
	//perque quan no estigui en rollover el text no quedi en gris

	if (((idTd.charAt(3)) == "1")&&(idTd.charCodeAt(4) > 58)){
		classHref=this.classElement[2];
	}
	else
	{
		classHref=this.classElement[3];
	}

	if (document.getElementById) { /* Navegadores con DOM- IE5.5,NS6*/
		if(this.actvFun==1){
			if(ev==0){
				document.getElementById(this.arg[1]).style.visibility='visible';
				document.getElementById(idTd).className=this.classElement[0];
				document.getElementById(idHref).className=this.classElement[2];
				if(this.tiempo!=0){
					clearTimeout(this.tiempo);
				}
			}else if(ev==1){
				document.getElementById(idTd).className=this.classElement[1];
				//document.getElementById(idHref).className=this.classElement[3];
				document.getElementById(idHref).className=classHref;
				this.tiempo=setTimeout(this.id+'.actvOpc("'+idTd+'","'+idHref+'",2)',this.arg[3]);
			}else{
				document.getElementById(this.arg[1]).style.visibility='hidden';
			}
		}else{
			this.actvFun=1;
			document.getElementById(this.arg[1]).style.visibility='visible';
		}
	}else if (document.all ) { /* Navegadores IE*/
		if(this.actvFun==1){
					if(ev==0){
						findObj(this.arg[1]).style.visibility='visible';
						findObj(idTd).className=this.classElement[0];
						findObj(idHref).className=this.classElement[2];
						if(this.tiempo!=0){
							clearTimeout(this.tiempo);
						}
					}else if(ev==1){
						findObj(idTd).className=this.classElement[1];
						//findObj(idHref).className=this.classElement[3];
						findObj(idHref).className=classHref;
						this.tiempo=setTimeout(this.id+'.actvOpc("'+idTd+'","'+idHref+'",2)',this.arg[3]);
					}else{
						findObj(this.arg[1]).style.visibility='hidden';
					}
				}else{
					this.actvFun=1;
					findObj(this.arg[1]).style.visibility='visible';
		}

	}
}


xControlMen.create.prototype.showOpc=function(idTd,idHref,ev){
	if (document.layers) { /* Navegadores NS4.5*/
		if(this.actvFun==1){
			if(ev==0){
				for(i=0;i<document.layers.length;i++) document.layers[i].visibility="hide";
				findObj(this.arg[1]).visibility="show";
				if(this.tiempo!=0){
					clearTimeout(this.tiempo);
				}
			}else if(ev==1){
				this.tiempo=setTimeout(this.id+'.showOpc("'+idTd+'","'+idHref+'",2)',this.arg[3]);
			}else{
				findObj(this.arg[1]).visibility="hide";
			}
		}else{
			this.actvFun=1;
			findObj(this.arg[1]).visibility="show";
		}
	}
}

function findObj(n, d) { //v4.0
  var p,i,x;  
  
  if(!d) d=document; 
  
  if( (p=n.indexOf("?"))>0 && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
  }
  
  // assigna objecte del document
  if(!(x=d[n]) && d.all) 
    x=d.all[n]; 
  
  // si l'objecte no existeix dins el document, busca als forms
  for (i=0;!x && i<d.forms.length;i++) {
    x=d.forms[i][n];
  }
  
  // si l'objecte no existeix als forms, busca dins de capes
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) {
    x=findObj(n,d.layers[i].document);
  }
    
  if(!x && document.getElementById) 
    x=document.getElementById(n); 
  
  return x;
}

//AFEGIT PER POSICIONA ELS LAYERS


var hide  = true;

function showhide(obj)
{
	var x = new getObj('testP');
	hide = !hide;
	x.style.visibility = (hide) ? 'hidden' : 'visible';
	setLyr(obj,'testP');
}

function setLyr(obj,lyr,OffsX,OffsY)
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	if(OffsX==null) OffsX=0;
	if(OffsY==null) OffsY=0;
	if (lyr == 'testP') newY -= 50;
	var ObjRetorn = new getObj(lyr);
	ObjRetorn.style.left = newX+OffsX;
	ObjRetorn.style.top = newY+OffsY;
}

function findPosX(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers) {
		curleft += obj.x;
    }
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
//	window.status = printstring;
	return curtop;
}


function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}
