/****************************Objetos items del Grupo de items (una capa DIV)

*******************************************************************************************/
function oItemJer(ident, it, enlace, padre, txt_enl)
{
this.ident = ident;
this.titulo = it;
this.enlace = enlace;
this.grPadre = padre;
this.enlazado = (typeof(txt_enl)=='object')?txt_enl:null;
this.descrip = (typeof(txt_enl)=='object')?null:txt_enl;
this.num = 0;
this.tipo = 0;  //0 Debajo, 1 Derecha
//Métodos
this.dibujar = oItemJer_dibujar;
this.entrar = oItemJer_entrar;
this.salir = oItemJer_salir;
this.pulsar = oItemJer_click;
this.resaltar = oItemJer_resaltar;
this.separadorNS4 = separadorNS4;

/*========================================================================================
FUNCION:		oItemJer_click()
ARGUMENTOS:		no
DEVUELVE:		nada
DESCRIPCION:	Simplemente dirige la página a donde indique la propiiedad enlace
========================================================================================*/
function oItemJer_click(obj)
{
  location.href = this.enlace;
}
/*========================================================================================
FUNCION:		oItemJer_salir(obj, evnt)
ARGUMENTOS:		obj: objeto que dispara la rutina
				evnt: objeto event.
DEVUELVE:		---
DESCRIPCION:	Actúa cuando el ratón abandona un elemento (oItemJer) del menú (oBrItems).
				Repone el estilo normal del elemento según la propiedad estNormal del 
				objeto padre (oGrItem al que pertenece este elemento).
				Si existiera un menú enlazado lo cierra
				Si existe una nota explicativa la cierra.
========================================================================================*/
function oItemJer_salir(obj, evnt)
{
var menuPadre = this.grPadre;
var capaPadre = menuPadre.cuerpoHtml;
var capaDescr = menuPadre.descrHtml;
menuPadre.actual = this.num;
switch (miNavegador.modVer) { 
case "IE4":
case "IE5":	
	capaDescr.style.visibility = "hidden";
	if (this.enlazado){
		if (!this.enlazado.cuerpoHtml.contains(event.toElement))
			this.enlazado.cerrar(evnt);
		event.cancelBubble = true; 	
		}	
	else
		this.resaltar(false);
	break;
case "NS5":
	capaDescr.style.visibility = "hidden";
	if (this.enlazado)
		{
		evnt.cancelBubble = true;	
		if (evnt.target.id != this.enlazado.cuerpoHtml.id )
			this.enlazado.cerrar(evnt);
		}	
	else
		this.resaltar(false);
	break;	
case "NS4":
	if (this.enlazado)
		{
		this.enlazado.ocultable = true;
		this.enlazado.ocultar(100);
		}
	else
		{
		capaDescr.visibility = "hidden";
		this.resaltar(false);	
		}
//	this.grPadre.ocultable = true;	
	menuPadre.actual = -1; 
	break;
default:
	alert("Navegador no soportado");
	}
}

/*========================================================================================
FUNCION:		oItemJer_entrar(obj, evnt)
ARGUMENTOS:		obj: objeto DIV o LAYER que hace la llamada
				evnt: evento (event)
DEVUELVE:		---
DESCRIPCION:	Se usa para cuando el ratón se sitúa sobre un oItemJer del menú. En resumen lo 
				que hace es 
				Resaltar el menú cambiando su estilo a indicado en la propiedad estActivo del
				objeto del que depende el oItemJer actual.
				Mostrar la nota explicativa ó
				Abrir el menú enlazado si existe				
========================================================================================*/
function oItemJer_entrar(obj, evnt)
{
var menuPadre = this.grPadre;
var posHor = 0; posVer= 0; limder=0;
capaPadre = menuPadre.cuerpoHtml;
capaDescr = menuPadre.descrHtml;
if (menuPadre.padre)	
	menuPadre.padre.grPadre.ocultable = false;	
this.resaltar(true);
menuPadre.actual = -1;

switch (miNavegador.modVer) { 
case "IE4":
case "IE5":
	posVer = capaPadre.offsetTop;
	event.cancelBubble = true;
case "NS5":
	posHor = parseInt(capaPadre.style.left);
	limder = (miNavegador.NS)?document.width:document.body.offsetWidth;
	if (this.enlazado)
		{
		if (this.enlazado.tipo == 0)
			posVer = posVer + capaPadre.offsetHeight; 
		else
			posHor += capaPadre.offsetWidth;
			
		if (posHor + this.enlazado.cuerpoHtml.offsetWidth +30>= limder)
			posHor = parseInt(capaPadre.style.left)- this.enlazado.cuerpoHtml.offsetWidth;
		this.enlazado.situar(posHor, obj.offsetTop+posVer); 
		this.enlazado.mostrar();
		this.enlazado.ocultable=false;
		menuPadre.ocultable = false
		}
	else{
		if (posHor + capaDescr.offsetWidth +50>= limder)
			{
			posHor = posHor - parseInt(capaPadre.style.width) - capaDescr.offsetWidth;
			posVer +=10;		
			}
		capaDescr.style.top = posVer+obj.offsetTop;
		capaDescr.style.left = posHor + capaPadre.offsetWidth;
		capaDescr.innerHTML = this.descrip;	
		capaDescr.style.visibility = "visible";
		}
	break;
case "NS4":
	capaItem = capaPadre.layers[this.ident];
	if(menuPadre.actual > 0 ) return false;
	menuPadre.actual = this.num;
	posHor = capaPadre.pageX;
	if (posHor+capaDescr.clip.width +50> screen.width)
			posHor =  capaPadre.pageX - capaDescr.clip.width -capaPadre.clip.width;
	capaDescr.pageY = capaItem.pageY;
	capaDescr.pageX = posHor + capaItem.clip.width;
	this.resaltar(true);
	if (this.enlazado)
		{
		if (this.enlazado.tipo == 0){
			posHor = parseInt(capaPadre.left);
			posVer = capaPadre.pageY + parseInt(capaPadre.clip.height);
			}
		else
			{
			posHor = parseInt(capaPadre.clip.width)+parseInt(capaPadre.left);
			posVer = capaPadre.pageY + capaItem.top;
			}	
		if (posHor + capaPadre.clip.width + 50 > screen.width)
			posHor =  capaPadre.pageX - this.enlazado.cuerpoHtml.clip.width;
		this.enlazado.situar(posHor, posVer); 
		this.enlazado.mostrar();
		this.enlazado.ocultable=false;
		menuPadre.ocultable = false
	    }
	else{
		//Escribe descripción
		capaDescr.document.open();
		capaDescr.document.write('<div id="par" class="'+menuPadre.estDesc + '">');
		capaDescr.document.write(this.descrip+" es la descripción"+'</div>'); 
		capaDescr.document.close();
		capaDescr.clip.height=capaDescr.document.layers[0].clip.height; 
		capaDescr.visibility = "visible"; 
		//Termina con la descripción
		}

	break;
default:
	alert("Navegador no soportado");
 } 
}
/*========================================================================================
FUNCION:		oItemJer_resaltar(sino)
ARGUMENTOS:		sino: true: resaltar, false poner en normal
DEVUELVE:		------
DESCRIPCION:	Activa o desactica el estilo resaltado del elemento oItemJer actual. Lo hace
				modificando los estilos CSS que lee desde el oGrItem del que depende este 
				elemento.
========================================================================================*/
function oItemJer_resaltar(sino)
{
var capaItem=objHtml(this.ident);
var cursor="pointer";
var menuPadre = this.grPadre, izq;
switch (miNavegador.modVer){
case "IE4":
case "IE5":
	cursor="hand";
case "NS5":
	if(sino)
		capaItem.className = menuPadre.estItemAct;
	else
		capaItem.className = menuPadre.estItemInac;
	capaItem.style.cursor=cursor;
	break;
case "NS4":
	ancho = menuPadre.cuerpoHtml.clip.width;
	if (document.classes[menuPadre.estBase].all.borderLeftWidth)
		ancho -= parseInt(document.classes[menuPadre.estBase].all.borderLeftWidth);
	if (document.classes[menuPadre.estBase].all.borderRightWidth)	
		ancho -= parseInt(document.classes[menuPadre.estBase].all.borderRightWidth);
	if (sino)
		{
		capaItem.bgColor = document.classes[menuPadre.estItemAct].all.backgroundColor;
		capaItem.clip.width = ancho;
		with(capaItem){ 
			document.open(); 
			if (this.num>0)
				this.separadorNS4(menuPadre.bordeinf, ancho);
			document.write('<a href = "'+this.enlace+'"');
			if (this.enlace=='')
				document.write('onclick="return false"');
			document.write('class="'+menuPadre.estItemAct+'">'); 
			document.write( this.titulo);
			document.write('</a>');
			document.close();
			}
		}
	else
		{
		capaItem.bgColor = document.classes[menuPadre.estItemInac].all.backgroundColor; 
		capaItem.width = ancho;
		with(capaItem){ 
			document.open();
			if (this.num>0)
				this.separadorNS4(menuPadre.bordeinf, ancho);
			document.write('<span class="'+menuPadre.estItemInac+'">'+this.titulo) 
			document.write('</span>')
			document.close(); 
			}
		}
	break;
	}		
}
/*========================================================================================
FUNCION:		oIem_dibujar(num, ancho, alto)
ARGUMENTOS:		num: número de orden del elemento
				ancho: ancho del elemento
				alto: alto del elemento (NN)
DEVUELVE:		---
DESCRIPCION:	Dibuja un objeto oItemJer, es decir, un elemento de un objeto oGrItem
========================================================================================*/
function oItemJer_dibujar(num, ancho, alto)
{
var ident = this.ident, nsColor; 
var menuPadre = this.grPadre;
var idobj = menuPadre.vble+".elementos["+num+"]";
var est = menuPadre.estItemInac; 
var izq, psup=1, anborde;
this.num = num;
switch (miNavegador.modVer){
case "IE4":
case "IE5":
	anborde = "100%";
case "NS5":	
	ancho = "100%";
	document.write('<a href = "'+this.enlace+'" ');
	if (this.enlace == '')
		document.write('onclick="return false" ');	
	document.write(' style="text-decoration:none;color:inherit">');
	document.write('<div onmouseover ="'+idobj+'.entrar(this,event)"');
	document.write(' onmouseout = "'+idobj+'.salir(this,event)"');
	document.write(' id="'+ident+'"  class="'+est+'" style="width:'+ancho+'px');
	document.write('; border-bottom:'+this.grPadre.bordeinf+';width:'+anborde+'">');
	document.write(this.titulo+'</div></a>'); 
	break;
case "NS4":
	izq=0;
	if (document.classes[menuPadre.estBase].all.borderLeftWidth)
		{
		ancho -= 2*parseInt(document.classes[menuPadre.estBase].all.borderLeftWidth);
		izq = parseInt(document.classes[menuPadre.estBase].all.borderLeftWidth);
		}
	if (document.classes[menuPadre.estInac].all.paddingLeft)
		ancho -= parseInt(document.classes[menuPadre.estInac].all.paddingLeft);
	if (document.classes[menuPadre.estBase].all.borderTopWidth && num==0)
		psup = parseInt(document.classes[menuPadre.estBase].all.borderTopWidth);
	if(num>0) psup = parseInt(menuPadre.bordeinf[0]);
	if (isNaN(psup)) psup=1; 
	nsColor=document.classes[menuPadre.estItemInac].all.backgroundColor
	document.write('<layer id="'+ident+'" class="'+est+'" top="'+(alto*num+psup)+'px"');
	document.write(' left="'+izq+'px" height="'+alto+'px"');
	document.write(' width="'+ancho+'" bgColor="'+nsColor+'"')
	document.write(' onmouseover ="'+ idobj+'.entrar(this.id,event)"');
	document.write(' onmouseout = "'+ idobj+'.salir(this.id,event)" >');
	if (num>0) this.separadorNS4(this.grPadre.bordeinf, ancho);
	document.write(this.titulo);
	document.write('</layer>');
	break;	
	}
}
/*========================================================================================
FUNCION:		separadorNS4(borde, ancho)
ARGUMENTOS:		borde: color del separador, estilo y grueso
				ancho: ancho del separador
DEVUELVE:		---
DESCRIPCION:	NN4 no usa bien los bordes de bloques así que se contruye una caja
				de alto el grueso del borde, ancho el ancho del borde y color el color 
				del borde
========================================================================================*/
function separadorNS4(borde, ancho)
	{
	document.write('<layer id="_brd" height="'+borde[0]+'" z-index="auto" left="0" top="0"');
	document.write('bgcolor="'+borde[2]+'" clip="0,0,'+ancho+','+borde[0]+'"></layer>');
	}
} 
//FIN DEL OBJETO oItemJer (Entradas de menú)
//****************************Objeto Contenedor de items 
function oGrItems(ident, estBase, estNorm, estAct, estDesc, vis) 
{ 
this.ident = ident+"_G"; 
this.descr = ident+"_D";
this.cuerpoHtml = null;
this.descrHtml = null;
this.vble = ident;
this.visible = vis;
this.estBase = estBase || null;
this.estItemAct = estAct;
this.estItemInac = estNorm;
this.estDesp = estNorm;  
this.estDesc = estDesc;
this.bordeinf = '';
this.actual = null;
this.padre = null;
this.ocultable = true;
this.elementos = new Array();
this.agregar = oGrItems_agregar; 
this.cerrar = oGrItems_cerrar; 
this.abrir = oGrItems_abrir;
this.dibujar= oGrItems_dibujar; 
this.situar = oGrItems_situar;
this.mostrar = oGrItems_mostrar;
this.ocultar = oGrItems_ocultar;
this.dibujaMenus = oGrItems_ponMenus;
/*
if (miNavegador.modVer == "NS4")
	{
	if (!document.classes[estBase].all.borderStyle)
		{
		document.classes[estBase].all.borderWidths(1);
		document.classes[estBase].all.borderStyle = "inset";
		}
	document.classes[estAct].all.fontSize = document.classes[estBase].all.fontSize;	
	document.classes[estAct].all.fontFamily = document.classes[estBase].all.fontFamily;	
	document.classes[estAct].all.fontWeight = document.classes[estBase].all.fontWeight;		
	document.classes[estAct].all.textDecoration = 'none';		
	document.classes[estNorm].all.fontSize = document.classes[estBase].all.fontSize;		
	document.classes[estNorm].all.fontFamily = document.classes[estBase].all.fontFamily;	
	document.classes[estNorm].all.fontWeight = document.classes[estBase].all.fontWeight;		
	document.classes[estNorm].all.textDecoration = 'none';	
	}	
*/
/*========================================================================================
FUNCION:		oGrItems_abrir(evnt) 
ARGUMENTOS:		evnt: evento que dispara este método (objeto event)
DEVUELVE:		---
DESCRIPCION:	Abre un cuadro con los elementos que forman el menú. Esta función está
				vinculada al evento de entrada del ratón al bloque del menú. 
				Es necesaria para los navegadores NN. Estos cuando abren un cuadro, abren 
				los cuadros de los que dependan (los que contienen a los item padres).
========================================================================================*/
function oGrItems_abrir(evnt) {
if (this.cuerpoHtml.style) 
	{ 
	if(evnt) evnt.cancelBubble = true; 
	if (this.padre) this.padre.grPadre.abrir();
	} 
else{
	if (this.padre)
		{
		this.padre.resaltar(true);
		this.padre.grPadre.abrir(evnt);
		}
	}
this.mostrar();
this.ocultable = false;
}
/*========================================================================================
FUNCION:		oGrItems_mostrar()
ARGUMENTOS:		---
DEVUELVE:		---
DESCRIPCION:	Hace visible el bloque HTML asociado a este objeto oGrItems, o sea, el cuadro
				con los elementos oItemJer contenidos en él.
========================================================================================*/
function oGrItems_mostrar() {
if (this.cuerpoHtml.style) 
	this.cuerpoHtml.style.visibility = "visible";
else
	this.cuerpoHtml.visibility = "show";
}

/*========================================================================================
FUNCION:		oGrItems_ocultar(cnt)
ARGUMENTOS:		cnt: tiempo que tardará en actuar la función (opcional).		
DEVUELVE:		---
DESCRIPCION:	Pone en oculta el bloque HTML asociado al objeto, o sea, el cuadro con los
				elementos oItemJer que forman el menú. El argumento indica el tiempo que debe
				esperar antes de cerrar la capa, si no existe el cierre es inmediato.Antes
				de cerrar comprueba que la capa tiene en true la propiedad ocultable.
========================================================================================*/
function oGrItems_ocultar(cnt) {
if (cnt)
	setTimeout(this.vble+".ocultar()", cnt)
else{
	if (this.ocultable)
		{
		if (this.cuerpoHtml.style) 
			this.cuerpoHtml.style.visibility = "hidden";
		else
			this.cuerpoHtml.visibility = "hide";
		this.padre.resaltar(false);	
		}
	}
}
/*========================================================================================
FUNCION:		oGrItems_cerrar(evnt)
ARGUMENTOS:		evnt: evento que dispara la función (si existe)
DEVUELVE:		---	
DESCRIPCION:	Cierra un grupo de items (oGrItems). Este cierre implica, no sólo ocultar 
				la capa asociada, sino también las enlazadas que estuvieran abiertas. El
				cierre se producirá cuando el ratón sale del bloque HTML asociado al objeto.
				Al cerrar un menú se cierran los menus padres del actual, si tienen su
				propiedad ocultable a true.
				MSIE comprueba si el ratón entra en un hijo o un padre antes de cerrar.
				En NS se cierran todos los relacionados, se abrirán si el movimiento del
				ratón lo requiere.
========================================================================================*/
function oGrItems_cerrar(evnt) { 
obItems = this.cuerpoHtml;
var hijos;
this.ocultable = true;
switch (miNavegador.modVer){
case "IE4":
case "IE5":
	if(this.padre)
		this.ocultable = (!obItems.contains(event.toElement) && 
					event.toElement.id != this.padre.ident);
case "NS5":
	evnt.cancelBubble = true;			
	if (this.padre)
		{
		if (this.ocultable)
			{
			this.ocultar(20);
			this.padre.grPadre.cerrar(evnt);
			}
		}	 
	break;
case "NS4":
	this.ocultable = true;
	if (this.padre!=null){
		this.ocultar(10);
		this.padre.grPadre.cerrar(evnt);
		}
	break;
	}
}
/*========================================================================================
FUNCION:		oGrItems_agregar(tit, enlace, desc, enlazado, tipo) 
ARGUMENTOS:		tit: cadena con el título que aparecerá en el item
				enlace: dirección URL a la que apunta el item.	
				desc: nota explicativa que aparecerá al pasar el ratón	
				enlazado: objeto oGrItems que se desplegará al pasar el ratón (si existe)
				tipo: 0, el enlazado se abre debajo; 1: se abre a la derecha
DEVUELVE:		---
DESCRIPCION:	Añade elementos al objeto oGrItem. Estos objetos pueden ser items de 
				menú que enlazan con otras páginas o pueden a su vez ser otros objetos 
				oGrItem, es decir, tener menus enlazados.
========================================================================================*/
function oGrItems_agregar(tit, enlace, desc_enl, tipo) 
{
var ind = this.elementos.length; 
var identit = this.ident+"_"+ind;
this.elementos[ind] = new oItemJer(identit, tit, enlace, this, desc_enl);
if (desc_enl.constructor==oGrItems)
	{ 
	desc_enl.padre = this.elementos[ind];
	desc_enl.tipo = tipo;
	}	
} 

/*========================================================================================
FUNCION:		oGrItems_situar(posX, posY)
ARGUMENTOS:		posX, posY : coordenadas de pantalla horizontal y vertical
DEVUELVE:		---
DESCRIPCION:	Situa en pantalla el bloque HTML asociado al objeto.
========================================================================================*/
function oGrItems_situar(posX, posY)
{
switch (miNavegador.modVer){
case "IE4":
case "IE5":
case "NS5":
	this.cuerpoHtml.style.left = posX;
	this.cuerpoHtml.style.top = posY;
	break;
case "NS4":
	this.cuerpoHtml.pageX = posX;
	this.cuerpoHtml.pageY = posY;
	break;
	}	
}
/*========================================================================================
FUNCION:		oGrItems_dibujar(posX, posY, ancho, alto) 
ARGUMENTOS:		posX, posY: situación del objeto
				ancho, alto: dimensiones del objeto
DEVUELVE:		---
DESCRIPCION:	Crea los elementos HTML asociados al objeto oGrItem. En el caso de MSIE o NS6
				utiliza bloques DIV, para NS4 se usan elementos LAYER. El bloque llevará 
				asociados eventos de ratón si es un bloque secundario (que se despliega a 
				petición de un elemento del menú). Los principales, siempre visibles, no 
				vinculan ningún evento.
========================================================================================*/
function oGrItems_dibujar(posX, posY, ancho, alto) { 
var ind;
var clase = 'class="'+this.estBase+'" '; 
var capa = this.ident; 
var activar='', desact='';
if (!this.visible)
	{
	activar = 'onmouseover ="'+this.vble+'.abrir(event)"'; 
	desact = 'onmouseout="'+this.vble+'.cerrar(event)"';
	}
switch (miNavegador.modVer){
case "IE4":
case "IE5":
case "NS5":   
	estilo = 'style="position:absolute; left: '+posX+'px; top:'+ posY; 
	estilo+= 'px; visibility: hidden; width:'+ancho+'px; height:'+alto+'px"'; 
	document.write('<div id= "' + this.ident+ '"' + estilo + clase + ' ');
	document.write(activar+' ' +desact +' >'); 
	for (ind in this.elementos)
			this.elementos[ind].dibujar(ind,ancho); 
	document.write('</div>');
	//Capa descripciones 
	document.write('<div id= "' + this.descr+'"');
	document.write(' class= "'+this.estDesc+'"');
	document.write(' style=" position:absolute; visibility:hidden">'); 
	document.write(this.ident+'</div>'); 
	this.cuerpoHtml = objHtml(this.ident);
	this.descrHtml = objHtml(this.descr);
	this.cuerpoHtml.style.height="auto";
	break;
case "NS4":
	capa = this.ident;
	altoit = parseInt(document.classes[this.estItemAct].all.fontSize)*1.2;
	if (document.classes[this.estItemAct].all.paddingTop)
	   altoit += parseInt(document.classes[this.estItemAct].all.paddingTop)
	if (document.classes[this.estItemAct].all.paddingBottom)
	   altoit += parseInt(document.classes[this.estItemAct].all.paddingBottom)    
	altocapa = this.elementos.length*altoit - 6;
	document.ids[capa].paddingTop = altocapa;
	document.ids[capa].width = ancho;	
	document.write('<layer id= "' +capa+ '" '+clase);
	document.write( activar + ' '+desact +' visibility="hidden" width="'+ancho+'"');
	document.write(' height="'+altocapa+'"');
	document.write(' bgcolor="'+document.classes[this.estBase].all.backgroundColor+'">');
	for (ind=0;ind < this.elementos.length; ind++)
		this.elementos[ind].dibujar(ind, ancho, altoit); 
	document.write('</layer>');
	document.layers[capa].top = posY; 
	document.layers[capa].left = posX;
	//Dibuja capa para la descripción del menú.
	document.write('<layer id="'+ this.descr +'" class= "'+this.estDesc+'" ');
	document.write('visibility="hidden">');
	document.write('menu: '+this.ident+'</layer>');
	this.cuerpoHtml = document.layers[this.ident];
	this.descrHtml = document.layers[this.descr];
	break;
	}
	if (this.visible) this.mostrar(null);
}
/*Dibuja un menú con todos sus enlazados*/
function oGrItems_ponMenus(px, py, an)
 {
 var ind;
 with (this){
	for (ind=0; ind<elementos.length; ind++)
		{
		if (elementos[ind].enlazado)
			elementos[ind].enlazado.dibujaMenus(px, py, an)
		}
	dibujar(px,py,an,0);
	}	
 }
}
/************************* FIN DEL OBJETO oGrItems********************/
