// ==============================================================
// UNOBTRUSIVE TOGGLE SECTIONS SCRIPT: TOGGLE v1.0
// (c)2004 Sergi Meseguer http://zigotica.com/ under CC license:
// http://creativecommons.org/licenses/by-sa/2.0/
// ==============================================================
// Just set htmlclass to element to be hidden/shown and 
// it'll make a link from the previous element
// ==============================================================

TOGGLE = {
	// edit text to append before linkable element
	showtxt : "",
	hidetxt : "",
	// edit html class name
	htmlclass : "desplegable",
	// 1: close all when opening any; 0: just toggle this.
	closeAll : 0,
	// secciones, por defecto las dejamos vacias, las inicializamos en cada pagina:
	//seccion : "",
	//subseccion : "",
	
	// you should not need to edit past this point
	// ======================================================
	getActive : function(){ 
		var items = document.getElementById("menu_principal").getElementsByTagName("A");
		for (var i = 0; i < items.length; i++) {
			var a = items[i];
/*			if(a.id == TOGGLE.subseccion) a.className = "activo"; */
			var id_enlace = '/' + a.id.replace(/-/g, '/')
			posicion=document.URL.indexOf(id_enlace)
/*			if(posicion > 0) a.className = "activo"; */
			if(posicion > 0 && a.id=="") a.className = "activoMain";
			else if(posicion > 0 && a.id!="") a.className = "activo";			
		}
	},
	
	start : function(){ 
		var togglers = EXTRAS.getElementsByClass(TOGGLE.htmlclass, null, 0);
		for (var i = 0; i < togglers.length; i++) {
			var box = togglers[i].previousSibling;
			//fix for Moz and line break/tab, etc:
			if(typeof box.innerHTML != "string") box = box.previousSibling; 
			var cont = togglers[i];
			//avoids currentStyle/computedStyle:
			cont.style.display = "block"; 
			TOGGLE.prepare(box,cont);
		}
		TOGGLE.getActive();
	},
	
	prepare : function(box,cont){ 
		var origtxt = box.innerHTML;
		
		if (cont.parentNode.id.indexOf("mp_") == 0) {
			fin_id = cont.parentNode.id.substring(3,cont.parentNode.id.length)
			id_con_barras = "/" + fin_id + "/"
		}
		posicion=document.URL.indexOf(id_con_barras)
/*		if (cont.parentNode.id == TOGGLE.seccion) cont.className = "desplegable activo";*/
		if (posicion > 0) cont.className = "desplegable activo";
		
		if (cont.className != "desplegable activo") cont.style.display = "none";
		box.innerHTML = TOGGLE.showtxt+origtxt;
		box.onclick = function(){
			/*TOGGLE.run(box,cont,origtxt);
			this.firstChild.style.backgroundPosition = "0px 0px"; // Parche para Explorer 1/2
			this.blur();
			return false;*/
		}
		
		/* Parches para Explorer 2/2 */
		box.onmouseout = function(){
			this.firstChild.style.backgroundPosition = "0px 0px";
		}
		box.onmouseover = function(){
			/*
			var title = UAH.getActiveStyleSheet();
			var rollMenu = -178; // Valor por defecto
			if ( title == "texto_medio"  ) {
				rollMenu = -232;
			} else if 	( title == "texto_mayor"  ) {
				rollMenu = -285;
			} 
			this.firstChild.style.backgroundPosition = rollMenu+"px 0px";
			*/
			this.firstChild.style.backgroundPosition = "-178px 0px";			
		}
		/* Fin Parches */
		
		// fix for IE5.x cursor property:
		if(navigator.appVersion.indexOf("MSIE 5") > -1 && !window.opera) box.style.cursor = "hand";
		else box.style.cursor = "pointer";
	},
	
	run : function(box,cont,origtxt) { 
		if(TOGGLE.closeAll == 1) {
			var togglers = EXTRAS.getElementsByClass(TOGGLE.htmlclass, null, 0);
			for (var i = 0; i < togglers.length; i++) if(togglers[i] != cont) togglers[i].style.display = "none";
		}
		if(cont.style.display == "block") {
			cont.style.display = "none";
			box.innerHTML = TOGGLE.showtxt+origtxt;
		}
		else {
			cont.style.display = "block";
			box.innerHTML = TOGGLE.hidetxt+origtxt;
		}
	}
}

// adds 1 or more elements to an array (IE only)
if(!Array.prototype.push)
{
	Array.prototype.push =  function()
	{
		var i;
		for(i=0; j=arguments[i]; i++) this[this.length] = j;
		return this.length;
	}
}
//if (document.getElementsByTagName) window.onload = TOGGLE.start;

var browserName=navigator.appName; // Get the Browser Name 

if(browserName=="Microsoft Internet Explorer") {
	window.onload=TOGGLE.start;
} else {
	// For Firefox 
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", TOGGLE.start, false); // Call init function in Firefox
	} 
} 



