// JavaScript Document
//
// Bryte 30.enero.2007
//
/*
//Variables de inicializacion ejemplo:

var eTab = $ES('a','menubar');					//La barra de menu visible
var eMenu = $ES('div','menu_1er_nivel');		//Los menus que aparecen de 1er. nivel
var eItemMenu = $ES('a','menu_1er_nivel');		//Las opciones de los menus de 1er. nivel
var eSubMenu = $ES('div','menu_2o_nivel');		//Los menus que aparecen en 2o. nivel
var retardo = 200;								//Tiempo que tardan los menus es esconderse
*/

function cerrarMenu(menu)
{
	menu.style.display = "none";
	menu.estado= 0;
}

function doMenu()
{

	if(typeof retardo == "undefined") retardo = 0;
	
	for (i=0; i< eTab.length; i++)
		{
			eTab[i].extend({
				inicio: function(){
					this.estado = 0;			
					this.numero = this.id.charAt(this.id.length-1);
					this.posXY = getAnchorPosition("tab_"+(i+1));
				},
				onmouseover: function(){
					if(eMenu[this.numero-1]) eMenu[this.numero-1].abrir();
				},
				onmouseout: function(){
					if(eMenu[this.numero-1]) eMenu[this.numero-1].cerrar();
				}
			});
			eTab[i].inicio();
		}
	// -----	
	for (i=0; i< eMenu.length; i++)
		{
			eMenu[i].extend({
				inicio: function(){
					this.estado = 0;				
					this.numero = this.id.charAt(this.id.length-1);
					this.i = i;
					this.myID = 0;
					this.style.display = "none";
					//this.style.top = eTab[i].posXY.y + 29 +  "px";
					this.style.left = eTab[i].posXY.x - 1 + "px";
					
					if(!document.all)
					{
						this.style.top = eTab[i].posXY.y + 13 + "px";
					}
					else
					{
						this.style.top = eTab[i].posXY.y + 29 +  "px";
					}
							
				},
				abrir: function(){
					if(this.estado == 0)
					{
						clearInterval(this.myID);
						this.style.display = "block";
					}
				},
				cerrar: function(){
					clearInterval(this.myID);
					this.myID = setTimeout("cerrarMenu(eMenu["+this.i+"])",retardo);
				},
				onmouseover: function(){
					clearInterval(this.myID);
					this.estado = 1;
				},
				onmouseout: function(){
					this.cerrar();
				}			
			});
			eMenu[i].inicio();
		}
	// -----		
		for (i=0; i< eItemMenu.length; i++)
		{
			eItemMenu[i].extend({
				inicio: function(){
					this.estado = 0;
					this.numero = this.id.charAt(this.id.length-1);
					this.padre = this.id.charAt(this.id.length-3);
					this.subMenu = -1;
				},
				onmouseover: function(){
					clearInterval(this.myID);
					this.posXY = getAnchorPosition(this.id);
					if(this.subMenu >= 0) eSubMenu[this.subMenu].abrir();
				},
				onmouseout: function(){
					if(this.subMenu >= 0) eSubMenu[this.subMenu].cerrar();
				}			
			});
			eItemMenu[i].inicio();
		}
	// -----
		for (i=0; i< eSubMenu.length; i++)
		{
			eSubMenu[i].extend({
				inicio: function(){
					this.estado = 0;
					this.numero = this.id.charAt(this.id.length-1);
					this.padre = this.id.charAt(this.id.length-3);
					this.i = i;
					this.padreN = -1;
					this.myID = -1;
					this.padreItemN = -1;
					
					for(n=0; n < eItemMenu.length; n++)
					{
						if (eItemMenu[n].numero == this.numero && eItemMenu[n].padre == this.padre) 
						{
							eItemMenu[n].subMenu = i;  // Le decimos al anchor que menu tiene que abrir
							this.padreItemN = n;
							for(m=0; m < eMenu.length; m++)
							{
								if(eMenu[m].numero == this.padre)
								{
									this.padreN = m;
								}
							}
						}
					}
					this.style.display = "none";
				},
				abrir: function(){
					clearInterval(this.myID);
					clearInterval(eMenu[this.padreN].myID);
					if(this.padreN == eMenu.length-1 )
					{
						//Es el ultimo a la derecha
						this.style.top = eItemMenu[this.padreItemN].posXY.y + 0 +  "px";
						this.style.left = eItemMenu[this.padreItemN].posXY.x + 195 +  "px";
					}
					else
					{
						this.style.top = eItemMenu[this.padreItemN].posXY.y +  0 +  "px";
						this.style.left = eItemMenu[this.padreItemN].posXY.x + 195 +  "px";					
					}
					this.style.display = "block";
				},
				cerrar: function(){
					clearInterval(this.myID);
					this.myID = setTimeout("cerrarMenu(eSubMenu["+this.i+"])",retardo);
					eMenu[this.padreN].cerrar();
				},
				onmouseover: function(){
					clearInterval(eMenu[this.padreN].myID);
					clearInterval(this.myID);
				},
				onmouseout: function(){
					this.cerrar();
				}
			});
			eSubMenu[i].inicio();
		}
	// -----	
}


// JavaScript Document