// ================================================================
// ACCESSIBLE COMBO MENU SCRIPT: SELMENU v1.0 
// (c)2004 Sergi Meseguer (http://zigotica.com/) under CC license:
// http://creativecommons.org/licenses/by-sa/2.0/
// Requires EXTRAS namespace (extras.js in this folder)
// ================================================================
var SELMENU = {
	
	selmenus : [], 	// [i][0]: parent element reference
			// [i][1]: title reference
			// [i][2]: list menu reference
			// only restriction: have *one* title and menu for each "selmenu"

	start : function(){ 
		var sm = EXTRAS.getElementsByClass("selmenu");
		for (var i = 0; i < sm.length; i++) {
			var caja = sm[i];

			var titulos = EXTRAS.getElementsByClass("selmenutitulo",caja);
			var titulo = titulos[0];

			var menus = EXTRAS.getElementsByClass("selmenulista",caja);
			var menu = menus[0];
			
			var enlaces = menu.getElementsByTagName("A");
			for (var a = 0; a < enlaces.length; a++) {
				enlaces[a].style.display = "block";
				enlaces[a].style.width = "100%"; 
			}
			SELMENU.selmenus.push([caja,titulo,menu]);
		}
			
		for (var z = 0; z < SELMENU.selmenus.length; z++) {
			SELMENU.prepare(SELMENU.selmenus[z][0],SELMENU.selmenus[z][1],SELMENU.selmenus[z][2],CSS.getStyle(SELMENU.selmenus[z][0], "zIndex"));
		}
	},
	
	prepare : function(menu,titulo,enlaces,z){ 
		if(z=="auto" || z==0) z=1;
		
		titulo.style.backgroundImage = "url(img/select.gif)";
		titulo.style.backgroundPosition =  "99% 2px";
		titulo.style.backgroundRepeat = "no-repeat";

		enlaces.style.display = "none";
		enlaces.style.position = "absolute";
		enlaces.style.top = parseInt(CSS.getStyle(titulo, "height")-1) + "px";
		enlaces.style.left = "0px";
		
		menu.onmouseover = function(){
			
			// ---------------------------------

			switch (menu.id){
			case "sel2":
				muestraIframe("bajo-sel2")
			break;

			case "sel3":
				muestraIframe("bajo-sel3")
			break;
			
			default : 
			}
			
			// ---------------------------------
		
			enlaces.style.display = "block";
			menu.style.zIndex = z+5555;
		}
		menu.onmouseout = function(){
		
			// ---------------------------------

			switch (menu.id){
			case "sel2":
				ocultaIframe("bajo-sel2")
			break;

			case "sel3":
				ocultaIframe("bajo-sel3")
			break;

			default : 
			}
			
			// ---------------------------------
		
			enlaces.style.display = "none";
			menu.style.zIndex = z;
		}
	}

}

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG() {
	for(var i=0; i<document.images.length; i++)
	{
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
	}
}

// Función que estrae las variables de la URL y las convierte en variables JS

function extraerVariablesURL() {
	cadVariables = location.search.substring(1,location.search.length);
	arrVariables = cadVariables.split("&");
	if (arrVariables.length > 1) {
		for (i=0; i<arrVariables.length; i++) {
		  arrVariableActual = arrVariables[i].split("=");
		  if (isNaN(parseFloat(arrVariableActual[1])))
		    eval(arrVariableActual[0]+"='"+unescape(arrVariableActual[1])+"';");
		  else
		    eval(arrVariableActual[0]+"="+arrVariableActual[1]+";");
		}
	}
}



if (document.getElementsByTagName) EXTRAS.addEvent(window, 'load', SELMENU.start, false);

/*

function mostrarMenualt() {
	mostrar("menualternativo");
}

function ocultarMenuprinc() {
	menu = "";
	extraerVariablesURL();

	if (menu != "" && menu != "bienvenida") {
	ocultar("menuprincipal");
	}

}



var navegador = navigator.appName

if (navegador == "Microsoft Internet Explorer") {
	if (document.getElementsByTagName) EXTRAS.addEvent(window, 'load', correctPNG, false);
} else {
	if (document.getElementsByTagName) EXTRAS.addEvent(window, 'load', mostrarMenualt, false);
	
	if (document.getElementsByTagName) EXTRAS.addEvent(window, 'load', ocultarMenuprinc, false);
}
*/

