// JavaScript Document
//
// Bryte 23.febrero.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.style.top = "-500px";
	menu.style.left = "-500px";
	menu.estado= 0;
	
	/* oculta mascara para IE <7 */
	if(menu == $('DivShim6').cual) {
		$('DivShim6').style.visibility = 'hidden';
		$('DivShim6').style.display = 'none';
	}
	/* */
}

function doMenu()
{
	if(typeof MenuUp == "undefined") MenuUp=false; // Por defecto el menu es hacia abajo

	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.hatXY = getAnchorPosition("hat_"+(i+1));
					this.shoeXY = getAnchorPosition("shoe_"+(i+1));
					this.largo = this.shoeXY.y - this.hatXY.y;
					/*------------------------------------------ */						

					if (MenuUp)
					{
						this.top = eTab[i].posXY.y - this.largo +  "px";
					}
					else
					{
						this.top = eTab[i].posXY.y + 24 +  "px";
					}					
					this.left = eTab[i].posXY.x + 0 + "px";
							
				},
				abrir: function(){
					if(this.estado == 0)
					{	
						clearInterval(this.myID);
						this.style.top = this.top;
						this.style.left = this.left;
						if (!MenuUp){
						/* */
							$('DivShim6').style.visibility = 'visible';
							$('DivShim6').style.display = 'block';
							$('DivShim6').style.top = this.top;
							$('DivShim6').style.left = this.left;
							$('DivShim6').style.width = 145 + "px";
							$('DivShim6').style.height = this.largo;
							$('DivShim6').style.zIndex = 3;
							$('DivShim6').cual = this;
						/* */
						}
					}
				},
				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;
					/* ------------------------------------------ */	 
					this.hatXY = getAnchorPosition("hat_"+ this.padre + "_" + this.numero);
					this.shoeXY = getAnchorPosition("shoe_"+ this.padre + "_" + this.numero);
					this.largo = this.shoeXY.y - this.hatXY.y;		
					/* ------------------------------------------ */	
					
					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;
								}
							}
						}
					}
				},
				abrir: function(){
					clearInterval(this.myID);
					clearInterval(eMenu[this.padreN].myID);
					if(this.padreN == eMenu.length-1 )
					{//Es el ultimo a la derecha
						if(MenuUp)
						{
							this.top = eItemMenu[this.padreItemN].posXY.y + 19 - this.largo +  "px";
							this.left = eItemMenu[this.padreItemN].posXY.x - 147 +  "px";							
						}
						else
						{
							this.top = eItemMenu[this.padreItemN].posXY.y - 1 +  "px";
							this.left = eItemMenu[this.padreItemN].posXY.x - 147 +  "px";
						}
					}
					else
					{//No es el ultimo a la derecha
						if(MenuUp)
						{
							this.top = eItemMenu[this.padreItemN].posXY.y + 19 - this.largo +  "px";
							this.left = eItemMenu[this.padreItemN].posXY.x + 145 +  "px";
						}
						else
						{
							this.top = eItemMenu[this.padreItemN].posXY.y - 1 +  "px";
							this.left = eItemMenu[this.padreItemN].posXY.x + 145 +  "px";
							/* */
							$('DivShim6').style.visibility = 'visible';
							$('DivShim6').style.display = 'block';
							$('DivShim6').style.top = this.top;
							$('DivShim6').style.left = this.left;
							$('DivShim6').style.height = this.largo;
							$('DivShim6').style.width = 145 + "px";
							$('DivShim6').style.zIndex = 3;
							$('DivShim6').cual = this;
							
							/* */
						}
					}
					this.style.top = this.top;
					this.style.left = this.left;
					
				},
				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