/*
 * SCRIPT DE CREACION DE MENUS (IBERMATICA)
 * 11/11/1999
 */

/* VBLES. GLOBALES PARA LOS MENUS */

// indica el navegador
var m_ns4=false;
var m_ie4=false;
document.domain="habe.org";

// para las capas
var m_doc="";
var m_estilo="";

// timer para retardar el esconder (ver m_esconder())
var m_tidEsconder=0;

// colores de los menus
var m_COLBORDE = "#802994";
var m_COLFONDO = "#E4B040";
var m_COLFONDOSEL = "#E4B040";
var m_COLTEXTO = "#802994";
var m_COLTEXTOSEL = "#FFFFFF";

// altura de cada item del menu
var m_ALTURA = 18;

// item seleccionado anterior
var m_anterior = "";
// array con los menus. Cada elemento menu tiene un array de items
var m_menus = new Array();

/*
 * Prepara el script para facilitar el manejo de las capas.
 * Da valor a las vbles m_ns4 y m_ie4. Si no es ninguno de estos, lo manda a una página de error por defecto.
 */
function m_layers () {
	m_ns4 = (document.layers)?1:0;
	m_ie4 = (document.all)?1:0;

	if ( !m_ns4 && !m_ie4 ) this.location.href="/habenet/naverror.htm";

	if (m_ns4) {
		m_doc="document.layers";
		m_estilo="";
		m_anchura=window.innerWidth;
		m_altura=window.innerHeight;
	}
	if (m_ie4) {
		m_doc="document.all";
		m_estilo=".style";
		m_anchura=document.body.clientWidth - 5;
		m_altura= document.body.clientHeight - 10;
	}
}

/*
 * Constructor del objeto m_Menu.
 */
function m_Menu ( ind, items ) {
	/* atributos */
	this.indice = ind;	// posición dentro del array de menús
	this.objitems = items;	// array de items del menú
	this.objmenu = null;	// referencia a la capa que representa este menú.
	/* métodos */
	this.mostrar = mnu_mostrar;	// hace visible el menú con todos sus items
	this.esconder = mnu_esconder; // esconde al menú y a todos sus items.
}

/*
 * Constructos del objeto m_Item.
 */
function m_Item(m_txt, m_url) {
	/* atributos */
	this.texto = m_txt;	// texto que aparece en el item del menú.
	this.url = m_url;	// url al que se va cuando se pincha en el item.
	this.objitem = null;	// referencia a la capa que representa este item cuando NO está seleccionado.
	this.objitemsel = null;	// referencia a la capa que representa este item cuando está seleccionado.
}

/*
 * Crea la estructura de menús y crea las capas que las representan.
 */
function m_generarmenus () {
	m_crearmenus ();
	m_escribirmenus ();

}

/*
 * Crea la estructura de menús.
 *
 * Funcionamiento por cada menú:
 * Se defined los items del menú.
 * Se construye el menú.
 * Se añaden resto de atributos necesarios:
 *  ancho del menú
 *  posición x
 *  posición y
 */
function m_crearmenus() {
	var id = top.idioma;

	var tmpArr;

	switch(id) {
	
	case 1: //euskera
		/* menu 0 */
		tmpArr = new Array(
			new m_Item("Helburuak","/hn_habenet/objetivos/indice_e.htm"),
			new m_Item("Hotline","/hn_habenet/hotline/indice_e.htm"),
			new m_Item("Download","/hn_habenet/download/indice_e.htm")
		);
		m_menus[0] = new m_Menu ( 0, tmpArr );
		m_menus[0].m_ancho=76;
		m_menus[0].posx=m_anchura - (m_menus[0].m_ancho + 15);
		m_menus[0].posy=5;

		/* menu 1 */
		tmpArr = new Array(
			new m_Item("Argitalpenak","/hn_servicios/publicaciones/indice_e.htm"),
			new m_Item("Liburutegia","/hn_servicios/biblioteca/indice_e.htm"),
			new m_Item("Didaktika","/hn_servicios/didactica/indice_e.htm"),
			new m_Item("Harpidetzak","/hn_servicios/suscripciones/indice_e.htm"),
			new m_Item("Lan-poltsa","/hn_servicios/bolsatrabajo/indice_e.htm"),
			new m_Item("Egonaldiak familietan","/hn_servicios/familias/indice_e.htm")
		);
		m_menus[1] = new m_Menu ( 1, tmpArr );
		m_menus[1].m_ancho=140;
		m_menus[1].posx=m_anchura - (m_menus[1].m_ancho + 15) - 66;
		m_menus[1].posy=5;

		/* menu 2 */
		tmpArr = new Array(
			new m_Item(".",".")
		);
		m_menus[2] = new m_Menu ( 2, tmpArr );
		m_menus[2].m_ancho=0;
		m_menus[2].posx=0;
		m_menus[2].posy=0;

		/* menu 3 */
		tmpArr = new Array(
			new m_Item("Gogoratu","/hn_noticias/tablon/indice_e.htm"),
			new m_Item("Prentsa-oharrak","http://www.argia.com/haria/htdocs/hariaegun.htm")
		);
		m_menus[3] = new m_Menu ( 3, tmpArr );
		m_menus[3].m_ancho=110;
		m_menus[3].posx=m_anchura - (m_menus[3].m_ancho + 15) - 246;
		m_menus[3].posy=5;
		
		break;
		
	  case 2: // castellano
		/* menu 0 */
		tmpArr = new Array(
			new m_Item("Objetivos","/hn_habenet/objetivos/indice_c.htm"),
			new m_Item("Hotline","/hn_habenet/hotline/indice_c.htm"),
			new m_Item("Download","/hn_habenet/download/indice_c.htm")
		);
		m_menus[0] = new m_Menu ( 0, tmpArr );
		m_menus[0].m_ancho=76;
		m_menus[0].posx=m_anchura - (m_menus[0].m_ancho + 15);
		m_menus[0].posy=5;

		/* menu 1 */
		tmpArr = new Array(
			new m_Item("Publicaciones","/hn_servicios/publicaciones/indice_e.htm"),
			new m_Item("Biblioteca","/hn_servicios/biblioteca/indice_c.htm"),
			new m_Item("Didáctica","/hn_servicios/didactica/indice_c.htm"),
			new m_Item("Suscripciones","/hn_servicios/suscripciones/indice_c.htm"),
			new m_Item("Bolsa de trabajo","/hn_servicios/bolsatrabajo/indice_e.htm"),
			new m_Item("Estancias en familias","/hn_servicios/familias/indice_c.htm")
		);
		m_menus[1] = new m_Menu ( 1, tmpArr );
		m_menus[1].m_ancho=130;
		m_menus[1].posx=m_anchura - (m_menus[1].m_ancho + 15) - 66;
		m_menus[1].posy=5;

		/* menu 2 */
		tmpArr = new Array(
			new m_Item(".",".")
		);
		m_menus[2] = new m_Menu ( 2, tmpArr );
		m_menus[2].m_ancho=0;
		m_menus[2].posx=0;
		m_menus[2].posy=0;

		/* menu 3 */
		tmpArr = new Array(
			new m_Item("Recordar","/hn_noticias/tablon/indice_c.htm"),
			new m_Item("Notas de prensa","http://www.argia.com/haria/htdocs/hariaegun.htm")
		);
		m_menus[3] = new m_Menu ( 3, tmpArr );
		m_menus[3].m_ancho=110;
		m_menus[3].posx=m_anchura - (m_menus[3].m_ancho + 15) - 246;
		m_menus[3].posy=5;

		break;
		
	  case 3: // frances
		/* menu 0 */
		tmpArr = new Array(
			new m_Item("Objetifs","/hn_habenet/objetivos/indice_f.htm"),
			new m_Item("Hotline","/hn_habenet/hotline/nodisponible.htm"),
			new m_Item("Download","/hn_habenet/download/indice_f.htm")
		);
		m_menus[0] = new m_Menu ( 0, tmpArr );
		m_menus[0].m_ancho=76;
		m_menus[0].posx=m_anchura - (m_menus[0].m_ancho + 15);
		m_menus[0].posy=5;

		/* menu 1 */
		tmpArr = new Array(
			new m_Item("Publications","/hn_servicios/publicaciones/indice_e.htm"),
			new m_Item("Bibliothèque","/hn_servicios/biblioteca/indice_f.htm"),
			new m_Item("Didactique","/hn_servicios/didactica/nodisponible.htm"),
			new m_Item("Abonnements","/hn_servicios/suscripciones/indice_f.htm"),
			new m_Item("Offres d'emplois","/hn_servicios/bolsatrabajo/indice_e.htm"),
			new m_Item("Séjours en familles","/hn_servicios/familias/indice_f.htm")
		);
		m_menus[1] = new m_Menu ( 1, tmpArr );
		m_menus[1].m_ancho=120;
		m_menus[1].posx=m_anchura - (m_menus[1].m_ancho + 15) - 66;
		m_menus[1].posy=5;

		/* menu 2 */
		tmpArr = new Array(
			new m_Item(".",".")
		);
		m_menus[2] = new m_Menu ( 2, tmpArr );
		m_menus[2].m_ancho=0;
		m_menus[2].posx=0;
		m_menus[2].posy=0;

		/* menu 3 */
		tmpArr = new Array(
			new m_Item("Souviens-toi","/hn_noticias/tablon/nodisponible.htm"),
			new m_Item("Notes de presse","http://www.argia.com/haria/htdocs/hariaegun.htm")
		);
		m_menus[3] = new m_Menu ( 3, tmpArr );
		m_menus[3].m_ancho=110;
		m_menus[3].posx=m_anchura - (m_menus[3].m_ancho + 15) - 246;
		m_menus[3].posy=5;
	  
		break;
		
	  case 4: // ingles
		/* menu 0 */
		tmpArr = new Array(
			new m_Item("Aims","/hn_habenet/objetivos/indice_i.htm"),
			new m_Item("Hotline","/hn_habenet/hotline/nodisponible.htm"),
			new m_Item("Download","/hn_habenet/download/indice_i.htm")
		);
		m_menus[0] = new m_Menu ( 0, tmpArr );
		m_menus[0].m_ancho=76;
		m_menus[0].posx=m_anchura - (m_menus[0].m_ancho + 15);
		m_menus[0].posy=5;

		/* menu 1 */
		tmpArr = new Array(
			new m_Item("Editions","/hn_servicios/publicaciones/indice_e.htm"),
			new m_Item("Library","/hn_servicios/biblioteca/indice_i.htm"),
			new m_Item("Didactics","/hn_servicios/didactica/nodisponible.htm"),
			new m_Item("Suscriptions","/hn_servicios/suscripciones/indice_i.htm"),
			new m_Item("Employment Bureau","/hn_servicios/bolsatrabajo/indice_e.htm"),
			new m_Item("Stays with Families","/hn_servicios/familias/indice_i.htm")
		);
		m_menus[1] = new m_Menu ( 1, tmpArr );
		m_menus[1].m_ancho=120;
		m_menus[1].posx=m_anchura - (m_menus[1].m_ancho + 15) - 66;
		m_menus[1].posy=5;

		/* menu 2 */
		tmpArr = new Array(
			new m_Item(".",".")
		);
		m_menus[2] = new m_Menu ( 2, tmpArr );
		m_menus[2].m_ancho=0;
		m_menus[2].posx=0;
		m_menus[2].posy=0;

		/* menu 3 */
		tmpArr = new Array(
			new m_Item("Remember","/hn_noticias/tablon/nodisponible.htm"),
			new m_Item("Press Notes","http://www.argia.com/haria/htdocs/hariaegun.htm")
		);
		m_menus[3] = new m_Menu ( 3, tmpArr );
		m_menus[3].m_ancho=110;
		m_menus[3].posx=m_anchura - (m_menus[3].m_ancho + 15) - 246;
		m_menus[3].posy=5;
	  
		break;
	}
}

/*
 * Crea las capas que representan a los menús.
 */
function m_escribirmenus () {
	var m_strMenu="";
	var m_strItem="";
	var m_strStyle="";

	/* creación de los estilos: item normal/seleccionado */
	// normal
	m_strStyle = "<STYLE TYPE='text/css'>A.mnormal{color: " + m_COLTEXTO + ";font-family: Arial;";
	m_strStyle += "font-size:9pt;";
	m_strStyle += "text-Decoration:none;font-weight:bold;}</STYLE>";
	document.write(m_strStyle);

	// seleccionado
	m_strStyle = "<STYLE TYPE='text/css'>A.msel{color: " + m_COLTEXTOSEL + ";font-family: Arial;";
	m_strStyle += "font-size:9pt;";
	m_strStyle += "text-Decoration:none;font-weight:bold;}</STYLE>";
	document.write(m_strStyle);

	/* creación de las capas de los menús y de items */
	for (i=0;i<m_menus.length;i++) {
		m_posx = m_menus[i].posx;
		m_posy = m_menus[i].posy;

		// capa del fondo del menú
		//m_strMenu = "<DIV ID='mnuid" + i + "' STYLE = 'position:absolute;layer-background-color:" + m_COLBORDE + ";background-color:" + m_COLBORDE + ";width:" + (m_menus[i].m_ancho + 2) + ";height:" + (m_ALTURA * m_menus[i].objitems.length + 2) + ";top:" + (m_posy - 1) + " ;left:" + (m_posx - 1) + ";visibility:hidden;z-index:500;'></DIV>";
		m_strMenu = "<DIV ID='mnuid" + i + "' STYLE = 'position:absolute;layer-background-color:" + m_COLBORDE + ";background-color:" + m_COLBORDE + ";width:" + (m_menus[i].m_ancho + 2) + ";height:" + (m_ALTURA * m_menus[i].objitems.length + 2) + ";top:0;left:0;visibility:hidden;z-index:500;'></DIV>";
		document.write(m_strMenu);

		if (m_ns4) eval(m_doc + '["mnuid' + i + '"]' + '.resizeTo(' + (m_menus[i].m_ancho + 2) + ',' + (m_ALTURA * m_menus[i].objitems.length + 2) + ')');
		m_menus [i].objmenu =  eval(m_doc + '["mnuid' + i + '"]' + m_estilo);	// relaciono la capa con la referencia a la capa del objeto menu

		// creación de las capas de los items. Dos por item: normal y seleccionado
		for (j=0;j<m_menus[i].objitems.length;j++) {
			tmp = 'mnusubid'+ i + '-' + j;

			// item normal
			m_strItem = "<DIV ID='" + tmp + "' STYLE = 'position:absolute;";
			if (m_ns4) m_strItem += "layer-background-color:" + m_COLFONDO + ";";
			if (m_ie4) m_strItem += "background-color:" + m_COLFONDO + ";";
			//m_strItem += "top:" + (m_posy + (j * m_ALTURA) ) + ";left:" + m_posx + ";visibility:hidden;width:" + m_menus[i].m_ancho + ";height:" + m_ALTURA + ";z-index:510;'> ";
			m_strItem += "top:0;left:0;visibility:hidden;width:" + m_menus[i].m_ancho + ";height:" + m_ALTURA + ";z-index:510;'> ";
			m_strItem += "<TABLE CELLPADDING='0' CELLSPACING='0' BORDER='0' WIDTH='" + (m_menus[i].m_ancho-3) + "'><TR><TD ALIGN='right'><A CLASS='mnormal'";
			m_strItem += " HREF='" + m_menus[i].objitems[j].url + "' target='principal'>&nbsp;" + m_menus[i].objitems[j].texto + "</A></TD></TR></TABLE></DIV>";
			document.write(m_strItem);

			eval(m_doc + '["' + tmp + '"].onmouseover=m_itemsel');	// cuando se produzca el evento onMouseOver, llama a la función m_itemsel
			eval(m_doc+'["' + tmp + '"]'+m_estilo+'.nombre="' + tmp + '"');	// atributo de la capa que uso para saber el menú que está seleccionado (ver m_itemsel())
			if (m_ns4) eval(m_doc + '["'+ tmp +'"]' + '.resizeTo(' + m_menus[i].m_ancho + ',' + m_ALTURA + ')');
			m_menus [i].objitems[j].objitem = eval(m_doc + '["' + tmp + '"]' + m_estilo);	// relaciono la capa con la referencia a la capa normal del objeto item

			// item seleccionado
			m_strItem = "<DIV ID='" + tmp + "A' STYLE = 'position:absolute;";
			if (m_ns4) m_strItem += "layer-background-color:" + m_COLFONDOSEL + ";color:" + m_COLTEXTOSEL + ";";
			if (m_ie4) m_strItem += "background-color:" + m_COLFONDOSEL + ";color:" + m_COLTEXTOSEL + ";";
			//m_strItem += "top:" + (m_posy + (j * m_ALTURA) ) + ";left:" + m_posx + ";visibility:hidden;width:" + m_menus[i].m_ancho + ";height:" + m_ALTURA + ";z-index:510;'> ";
			m_strItem += "top:0;left:0;visibility:hidden;width:" + m_menus[i].m_ancho + ";height:" + m_ALTURA + ";z-index:510;'> ";
			m_strItem += "<TABLE CELLPADDING='0' CELLSPACING='0' BORDER='0' WIDTH='" + (m_menus[i].m_ancho-3) + "'><TR><TD ALIGN='right'><A  ALIGN='right' CLASS='msel'";
			m_strItem += " HREF='" + m_menus[i].objitems[j].url + "' target='principal'>&nbsp;" + m_menus[i].objitems[j].texto + "</A></TD></TR></TABLE></DIV>";
			document.write(m_strItem);

			if (m_ns4) eval(m_doc + '["'+ tmp +'A"]' + '.resizeTo(' + m_menus[i].m_ancho + ',' + m_ALTURA + ')');
			m_menus [i].objitems[j].objitemsel = eval(m_doc + '["' + tmp + 'A"]' + m_estilo);	// relaciono la capa con la referencia a la capa seleccionada del objeto item
		}
	}

}

/*
 * Método que se lanza cuando se selecciona un item.
 * Desactiva el contador que hace esconder la capa,
 * esconde la capa seleccionada del item seleccionado anterior,
 * y muestra la capa seleccionada del item actual.
 */
function m_itemsel(evnt) {
	m_noesconder();

	if (m_anterior!='') eval(m_doc+'["' + m_anterior + '"]'+m_estilo+'.visibility="hidden"');
	if (m_ns4) tmp = this.nombre + 'A';
	if (m_ie4) tmp = this.style.nombre + 'A';

	eval(m_doc+'["' + tmp + '"]'+m_estilo+'.visibility="visible"');
	m_anterior = tmp;

	m_esconder();	// Para que los menús se escondan después de un determinado tiempo si no ocurre ningún evento que diga lo contrario.
	return true;
}

/*
 * Hace desaparecer los menús después de 5 segundos.
 */
function m_esconder() {
	if (m_tidEsconder) clearTimeout (m_tidEsconder);
	m_tidEsconder = setTimeout("m_escondertodo()",2000);
}

/*
 * Desactiva el contador que hace desaparecer los menús.
 */
function m_noesconder() {

 	if (m_tidEsconder) clearTimeout(m_tidEsconder);

}

/*
 * Muestra el menú pasado como parámetro con todos sus items.
 */
function m_mostrar(m_mnuid) {
	m_noesconder();//a
	m_menus[m_mnuid].mostrar()
}

/*
 * Método del objeto m_Menu. Muestra el menú con todos sus items.
 */
function mnu_mostrar(){
  
	m_escondertodo ();	// esconde todos los menus.

	if (top.oculto.bs_cargado) top.barrasuperior.encender ('menu' + this.indice);	// enciende la imagen asociada al menú de la barrasuperior.

	/* obtención de la posicionx y posiciony que hay que dar a la capa, teniendo en cuenta el desplazamiento del documento dentro de la ventana */
	if (m_ns4) {
			tmpx = window.pageXOffset + this.posx - 1;
			tmpy = window.pageYOffset + this.posy - 1;
	}
	if (m_ie4) {
			tmpx = window.document.body.scrollLeft + this.posx - 1;
			tmpy = window.document.body.scrollTop + this.posy - 1;
	}
	this.objmenu.left=tmpx;
	this.objmenu.top=tmpy;
    
	/* muestra la capa del menú */
	this.objmenu.visibility="visible";
	var j=0;
	/* muestra la capa de los items del menú */
	for (j=0;j < this.objitems.length ;j++ ) {
		if (m_ns4) {
			tmpx = window.pageXOffset + this.posx;
			tmpy = window.pageYOffset + this.posy + (j * m_ALTURA);
		}
		if (m_ie4) {
			tmpx = window.document.body.scrollLeft + this.posx;
			tmpy = window.document.body.scrollTop + this.posy + (j * m_ALTURA);
		}
		this.objitems[j].objitem.left = tmpx;
		this.objitems[j].objitem.top = tmpy;
		this.objitems[j].objitem.visibility="visible";
		// calcula también las posiciones x e y para las capas item-seleccionado.
		this.objitems[j].objitemsel.left = tmpx;
		this.objitems[j].objitemsel.top = tmpy;
	}

	m_esconder();	// Para que los menús se escondan después de un determinado tiempo si no ocurre ningún evento que diga lo contrario.
}

/*
 * Método del objeto m_Menu. Esconde el menú con todos sus items.
 */
function mnu_esconder(){
	var j=0;

	for (j=0;j < this.objitems.length ;j++ ) {
		this.objitems[j].objitem.visibility="hidden";
		this.objitems[j].objitemsel.visibility="hidden";
	}
	this.objmenu.visibility="hidden";
	if (top.oculto.bs_cargado) top.barrasuperior.apagar ('menu' + this.indice);	// apaga la imagen asociada al menú de la barrasuperior.
}

/*
 * Esconde todos los menús.
 */
function m_escondertodo() {
	m_noesconder();

	for (i=0;i<m_menus.length;i++) {
		m_menus[i].esconder ();
	}
}

/*
 * Función llamada desde la página que contendrá los menús.
 * Se encarga de preparar los menús.
 */
function mnu_inicio(){
	m_layers ();
	m_generarmenus();

}

