//
//	Menu Class Declaration
//	- initialize()
//	- change()
//
//

var Menu = Class.create();

Menu.prototype = {
	initialize: function() {
		this.obj = $('menu');
		this.inicial = menu_default;
		this.actual = menu_visto;
		this.sactual = submenu_visto;


		var objMenu = document.createDocumentFragment();

		var objTabla = document.createElement('table');
		objTabla.setAttribute('id', 'menu');
		objTabla.setAttribute('cellspacing', 0);
		objTabla.cellSpacing = 0;
		objTabla.setAttribute('cellpadding', 0);
		objTabla.cellPadding = 0;
		objMenu.appendChild(objTabla);

		var objTHead = document.createElement('thead');
		objTabla.appendChild(objTHead);

		var thead_tr = document.createElement('tr');
		objTHead.appendChild(thead_tr);


		var tbody = document.createElement('tbody');
		objTabla.appendChild(tbody);

		var tbody_tr0 = document.createElement('tr');
		tbody.appendChild(tbody_tr0);

		var tbody_tr0_td = document.createElement('td');
		tbody_tr0_td.setAttribute('height', '5');
		tbody_tr0_td.setAttribute('colspan', 7);
		tbody_tr0_td.colSpan = 7;
		tbody_tr0.appendChild(tbody_tr0_td);


		var tbody_tr = document.createElement('tr');
		tbody_tr.setAttribute('id', 'submenu');
		tbody.appendChild(tbody_tr);


		var tbody_tr_td = document.createElement('td');
		tbody_tr_td.className = 'on';
		tbody_tr_td.setAttribute('align', 'right');
		tbody_tr_td.setAttribute('valign', 'bottom');
		tbody_tr_td.setAttribute('colspan', 7);
		tbody_tr_td.colSpan = 7;
		tbody_tr.appendChild(tbody_tr_td);

		var tbody_tr_td_div = document.createElement('div');
		tbody_tr_td_div.setAttribute('id', 'submenu-default');
		tbody_tr_td_div.className = ((this.inicial != "default") ? 'off': 'on');
		tbody_tr_td.appendChild(tbody_tr_td_div);


		for (c = 0, cols = 0; c < this.obj.childNodes.length; c++) {
			if ((this.obj.childNodes[c].nodeType == 1) && (this.obj.childNodes[c].nodeName == "LI")) {
				var opcion = this.obj.childNodes[c].firstChild.firstChild.nodeValue.toLowerCase();
				var href = this.obj.childNodes[c].firstChild.getAttribute('href');

				var tab_th = document.createElement('th');
				tab_th.setAttribute('id', 'menu-'+opcion);
				tab_th.className =((opcion == this.actual)?'on':'off');
				thead_tr.appendChild(tab_th);

				var tab_th_a = document.createElement('a');
				tab_th_a.setAttribute('href', href);
				tab_th_a.onmouseover = new Function("myMenu.change('"+opcion+"');return false;");
				tab_th.appendChild(tab_th_a);

				var tab_th_a_txt = document.createTextNode(opcion);
				tab_th_a.appendChild(tab_th_a_txt);


				var smenu_div = document.createElement('div');

				if (this.obj.childNodes[c].getElementsByTagName('ul').length) {
					var ul = this.obj.childNodes[c].getElementsByTagName('ul').item(0);

					for (k = 0, sc = 1; k < ul.childNodes.length; k++) {
						if ((ul.childNodes[k].nodeType == 1) && (ul.childNodes[k].nodeName == "LI")) {
							var smenu_div_a = ul.childNodes[k].firstChild.cloneNode(true);
							smenu_div_a.className =(((sc == this.sactual)&&(opcion == this.actual))?'on':'off');
							smenu_div.appendChild(smenu_div_a);

							sc++;
						}
					}
				}

				smenu_div.setAttribute('id', 'submenu-'+opcion);
				smenu_div.className = ((opcion != this.inicial) ? 'off': 'on');
				tbody_tr_td.appendChild(smenu_div);

				cols++;
			}
		}



		var td_0 = document.createElement('td');
		td_0.setAttribute('width', 75);
		td_0.onmouseover = new Function("myMenu.change('"+this.inicial+"');return false;");
		thead_tr.insertBefore(td_0, thead_tr.firstChild);


		this.obj.parentNode.replaceChild(objMenu, this.obj);
	}, 


	change: function(id) {
		if (id != this.actual) {
			if ((this.actual != 'default') || ((this.actual == 'default') && (this.inicial == 'default'))) {
				if (this.actual != 'default') $('menu-'+this.actual).className = 'off';
				$('submenu-'+this.actual).className = 'off';
			}

			if ((id != 'default') || ((id == 'default') && (this.inicial == 'default'))) {
				if (id != 'default') $('menu-'+id).className = 'on';
				$('submenu-'+id).className = 'on';
			}

			this.actual = id;
		}
	}
}

function setMenu() { myMenu = new Menu(); }
Event.observe(window, 'load', setMenu, false);


function popUp (url, popup_width, popup_height) {
	var modo = "width=" + popup_width + ",height=" + popup_height + ",status=no,menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,directories=no"
	var popup = window.open (url, "popup", modo);
}

