UAH = {

	// ======================================================
	// edit html class name for expandable element
	htmlclass : "desplegable",
	opened : "/ambientales/imagenes/iconos/flecha_opened.gif",
	closed : "/ambientales/imagenes/iconos/flecha_closed.gif",
	// edit html class name for activator
	acticlass : "activator",
	// edit images path for text sizer
	imgsizemas : "/ambientales/imagenes/iconos/A_3.gif",
	imgsizeigual : "/ambientales/imagenes/iconos/A_2.gif",
	imgsizemenos : "/ambientales/imagenes/iconos/A_1.gif",
	// edit text sizes
	sizemas : "18px",
	sizeigual : "16px",
	sizemenos : "14px",
	// you should not need to edit past this point
	// ======================================================
	start : function(){ 
		var cursor = (document.all)?"hand":"pointer";
		
		// add text sizers
		var sizers = "<img src='"+UAH.imgsizemenos+"' onclick='UAH.txtSizer(\""+UAH.sizemenos+"\")' style='cursor:"+cursor+"'>";
		sizers += "<img src='"+UAH.imgsizeigual+"' onclick='UAH.txtSizer(\""+UAH.sizeigual+"\")' style='cursor:"+cursor+"'>";
		sizers += "<img src='"+UAH.imgsizemas+"' onclick='UAH.txtSizer(\""+UAH.sizemas+"\")' style='cursor:"+cursor+"'>";
		var div = document.createElement("DIV");
		div.id = "txtsizer";
		div.innerHTML = sizers;
		if(!window.opera) document.getElementById("rightnav").insertBefore(div, document.getElementById("enlacesgraficos"));

		// set user text size from cookie (if exists)
		if(Cookie.get("UAH_txtsize")) document.body.style.fontSize = Cookie.get("UAH_txtsize");
		
		// prepare expandable menu elements
		var expandibles = UAH.hasClass(UAH.htmlclass);
		for (var i = 0; i < expandibles.length; i++) {
			
			// getting elements:
			var sublist = expandibles[i];
			var parentlist = sublist.parentNode;
			var children = parentlist.childNodes;
			for (var z = 0; z < children.length; z++) {
				if(children[z].nodeType==1) {
					var container =  children[z];
					break;
				}
			}

			//avoids currentStyle/computedStyle:
			sublist.style.display = "none"; 

			// create actuator image:
			var img = document.createElement("IMG"); 
				img.src = UAH.opened;
				img.setAttribute ("width","7px");
				img.setAttribute ("height","7px");
			var txt = document.createTextNode(" "); 
			container.appendChild(txt);
			container.appendChild(img);
			
			// add onmouseover cursor:
			container.style.cursor = cursor; 

			// add class to activator:
			if(container.className) container.className += " " + UAH.acticlass; 
			else container.className = UAH.acticlass; 
			
			// prepare events for each element:
			UAH.prepare(container,sublist,img); 
		}
	},
	
	prepare : function(container,sublist,img) { 
		container.onclick = function(){ 
			UAH.run(container,sublist,img); 
		}
	}, 
	
	run : function(container,sublist,img) { 
		//if sublist is visible, then just hide it:
		if(sublist.style.display == "block") {
			container.style.color = "#1E2D3B";
			container.style.fontWeight = "normal";
			sublist.style.display = "none";
			img.src = UAH.opened;
		}
			
		//else hide all and then show this one:
		else {	
			// first we hide all submenus
			var expandibles = UAH.hasClass(UAH.htmlclass);
			for (var e = 0; e < expandibles.length; e++) {
				var tobehidden = expandibles[e];
				tobehidden.style.display = "none";
			}
				
			// then we re-style all activators
			var activators = UAH.hasClass(UAH.acticlass);
			for (var a = 0; a < activators.length; a++) {
				var toberestyled = activators[a];
				toberestyled.style.color = "#1E2D3B";
				toberestyled.style.fontWeight = "normal";
			}
				
			// then we change all image activators to closed
			var imgs = document.getElementById("menu").getElementsByTagName("IMG");
			for (var i = 0; i < imgs.length; i++) {
				var myimg = imgs[i];
				myimg.src = UAH.opened;
			}

			// then we show this sublist again
			container.style.color = "#88D402";
			container.style.fontWeight = "bold";
			sublist.style.display = "block";
			img.src = UAH.closed;
		}
	}, 
	
	txtSizer : function(size){
		document.body.style.fontSize = size;
		Cookie.set("UAH_txtsize",size,1);
	},

	// Method adapted from Dan Pupius (pupius.co.uk):
	hasClass : function(className,node) {
		if(!node) node=document;
		var refTags = document.all ? document.all : node.getElementsByTagName("*");
		var retVal = new Array();
		for(var z=0;z<refTags.length;z++) {
			//if(refTags[z].className == className) 
			if(refTags[z].className.indexOf(className) > -1) 
			retVal.push(refTags[z]);
		}
		return retVal; 
	},
	
		popThisUp : function(obj) {
			obj.onclick = function() {
				window.open(obj.href, '');
				return false;
			}
	},

	autoPopup : function() {
			var pops = EXTRAS.getElementsByClass('externa',null , 0);
			for (var i = 0; i < pops.length; i++) {
					UAH.popThisUp(pops[i]);
			}
	}	
	
}

EXTRAS = {
	
	addEvent : function(obj, evType, fn, useCapture){
		if (obj.addEventListener){
			obj.addEventListener(evType, fn, useCapture);
			return true;
		} 
		else if (obj.attachEvent){
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		} 
		else {
			return false;
		}
	}, 	
	
	getElementsByClass : function(className,node,equal,except) {
			if(!node) node=document;
			// follows UGLY hack to fix IE5
			if(navigator.appVersion.indexOf("MSIE 5")>-1) var refTags = document.all;
			else var refTags = node.getElementsByTagName("*") ? node.getElementsByTagName("*") : document.all;
		 
			var retVal = new Array();
			for(var z=0;z< refTags.length;z++) {
					if(
					(equal==1 && refTags[z].className == className)
					|| (equal==0 && !except && refTags[z].className.indexOf(className) != -1)
					|| (equal==0 && refTags[z].className.indexOf(className) != -1 && refTags[z].className.indexOf(except) == -1)
					)
					retVal.push(refTags[z]);
			}
			return retVal;
	}


}

// Cookie namespace, by Dave Schontzler, www.stilleye.com
Cookie = {
	set : function(name,value,days,path)
	{
		var ex = "";
		if(days)
		{
			var d = new Date();
			d.setTime(d.getTime()+(days*24*60*60*1000));
			ex = "; expires="+d.toGMTString();
		}
		path = path ? path : "/";
		document.cookie = name + "=" + escape(value) + ex + "; path=" + path;
	},
	
	get : function(name)
	{
		var c = document.cookie.split(';');
		var wh = name + '=';
		for(i=0;(j=c[i]);i++)
		{
			while(j.charAt(0)==' ') j = j.substring(1, j.length);
			if(j.indexOf(wh)==0) return unescape(j.substring(wh.length));
		}
		return null;
	},
	
	kill : function(name) { Cookie.set(name,'',-1); }
}


// 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 = UAH.start;

