var MENU = 
{
	init : function()
	{	
		if (document.getElementById('menu'))
		{
			var lnk1nivel = document.getElementById('menu').getElementsByTagName('a');
			
			for (cont = 0; cont < lnk1nivel.length; ++cont)
			{
				document.getElementById(lnk1nivel[cont].id).onmouseover = function()
				{
					var img = document.getElementById('img'+this.id);
					if (img.src.indexOf('_on') < 0)
					{
						var ruta = img.src.substring(0,img.src.lastIndexOf('.'))+'_on'+img.src.substring(img.src.lastIndexOf('.'),img.src.length);
						img.src = ruta;
					}
				}
				document.getElementById(lnk1nivel[cont].id).onmouseout = function()
				{
					if (document.getElementById('capaSub'+this.id).className != 'visible')
					{
						var ruta = document.getElementById('img'+this.id).src.replace('_on','');
						document.getElementById('img'+this.id).src = ruta;
					}
				}
				document.getElementById(lnk1nivel[cont].id).onclick = function()
				{
					MENU.ocultarImagenesMenu(this.id);
					MENU.ocultarSubMenus();
					document.getElementById('capaSub'+this.id).className = 'visible';
				}				
			}
		}
	},
	ocultarSubMenus : function()
	{
		var subcapas = document.getElementById('submenu').getElementsByTagName('div');
		for (cont = 0; cont<subcapas.length; ++cont)
		{
			document.getElementById(subcapas[cont].id).className = 'oculto';
		}
	},
	ocultarImagenesMenu : function(opcion)
	{
		var img1nivel = document.getElementById('menu').getElementsByTagName('img');
		for (cont = 0; cont<img1nivel.length; ++cont)
		{
			if ('img'+opcion != img1nivel[cont].id)
			document.getElementById(img1nivel[cont].id).src = document.getElementById(img1nivel[cont].id).src.replace('_on','');
		}
	}
}

/* LOAD */

function addLoadEvent(fn)
 {
	var old = window.onload;
	if(typeof window.onload != 'function')
		window.onload = fn;
	else
		window.onload = function()
		 {
			old();
			fn();
		 }
 }

addLoadEvent( function() { MENU.init(); } );
