
// JavaScript Document

FernandoMenuClass = function() {
	// Saves the ids of the Menus that are opened
	this.submenusshown = new Array();	
	
	// id count
	this.idcount = 0;
	
	// Menu itens and submenu itens array
	this.data = null;


	document.write('<table cellspacing="0" cellpadding="0" border="0" id="fernandomenu_back" class="fernandomenu_back" onmousemove="fernandomenu.HideBack();"><tr><td></td></tr></table>');
	document.write('<div id="fernandomenu1" class="fernandomenu">');
	document.write('</div>');
	document.write('<div id="fernandomenu2" class="fernandomenu">');
	document.write('</div>');
	document.write('<div id="fernandomenu3" class="fernandomenu">');
	document.write('</div>');
	document.write('<div id="fernandomenu4" class="fernandomenu">');
	document.write('</div>');
	document.write('<div id="fernandomenu5" class="fernandomenu">');
	document.write('</div>');
	document.write('<div id="fernandomenu6" class="fernandomenu">');
	document.write('</div>');

	// Shows a menu or submenu
	this.ShowMenu = function (id, obj, issubmenu, column) {
		if (typeof issubmenu == 'undefined') issubmenu = false;
		if (typeof column == 'undefined') column = 1;
		
		// Shows invisible background that cover all the document area
		this.ShowBack()
		
		// Makes children menus that are not focused, hidden
		this.ClearMenus(column);
		
		if (id == '') return;
		
		this.html = '<table border="0" cellspacing="0" cellpadding="0">';
		for (this.ShowMenu.i = 0; this.ShowMenu.i < this.data.length; this.ShowMenu.i++) {
			if (this.data[this.ShowMenu.i][0] != id) continue;
			
			this.idcount++;
			this.img = "";
			this.submenu = "";
			if (this.data[this.ShowMenu.i][3] != '') {
				this.img = '<img src="my-data/posts/seta.gif" align="right" border="0" width="9" height="25">';
				this.submenu = 'fernandomenu.ShowMenu(' + this.data[this.ShowMenu.i][3] + ', this, true, ' + (column+1) + ');';
			} else {
				this.submenu = 'fernandomenu.ClearMenus(' + (column+1) + ');';
			}
			this.html += '<tr><td id="item'+ (this.idcount) +'" onmouseover="fernandomenu.Hilight(this, ' + this.ShowMenu.i + ',' + "'item" + (this.idcount) + "'" +', ' + column+'); ' + this.submenu + '"><a href="' + this.data[this.ShowMenu.i][2] + '">' + this.img + this.data[this.ShowMenu.i][1] + '</a></td></tr>';

			this.data[this.ShowMenu.i][4] = column;
		}
		this.html += '</table>';
		
	
		this.pos = this.FindPos(obj);
		this.fm = document.getElementById('fernandomenu'+this.ReturnOpened());
		if (this.fm) {
			this.fm.innerHTML = this.html;
			if (issubmenu == true)
				this.fm.style.left = (this.pos[0]+obj.offsetWidth+1) + 'px';
			else
				this.fm.style.left = (this.pos[0]) + 'px';				
		
			if (issubmenu == true)
				this.fm.style.top = (this.pos[1]) + 'px';
			else
				this.fm.style.top = (this.pos[1]+obj.offsetHeight) + 'px';
			this.fm.style.visibility = "visible";
		}

	}
	
	this.Hilight = function(obj, index, id, column) {
		for (this.i = 0; this.i < this.data.length; this.i++) {
			if (this.data[this.i][4] >= column) {
				if (this.data[this.i][5] != null) {
					this.UnHilight(this.data[this.i][5]);
					this.data[this.i][5] = null;
				}
			}
		}
		
		obj.className = 'fernandomenu_over';
		this.data[index][5] = id;
	}
	
	this.UnHilight = function(id) {
		this.objUH = document.getElementById(id);
		if (this.objUH) {
			this.objUH.className = 'fernandomenu_out';
		}
	}
	
	this.ShowBack = function() {
		this.objBack = document.getElementById('fernandomenu_back');
		if (this.objBack) {
			if (this.objBack.style.visibility != 'visible') {
				this.objBack.style.visibility = 'visible';	
				this.objBack.style.display = 'block';
				this.objBack.style.top = '0px';
				this.objBack.style.left = '0px';
				this.objBack.style.width = (document.body.offsetWidth-25)+'px';
				this.objBack.style.height = (document.body.offsetHeight-28)+'px';
			}
		}
		
		this.pgBar = document.getElementById('pagebar');
		if (this.pgBar) {
			this.pgBar.style.position = 'relative';	
		}
	}
	this.HideBack = function() {
		this.objBack = document.getElementById('fernandomenu_back');
		if (this.objBack) {
			this.objBack.style.visibility = 'hidden';
			this.objBack.style.display = 'none';
			
			this.ClearMenus(1);
		}
		
		this.pgBar = document.getElementById('pagebar');
		if (this.pgBar) {
			this.pgBar.style.position = 'static';
		}
	}
	
	// Returns the number of openned menus we have
	this.ReturnOpened = function() {
/*		this.current = -1;
		this.count = 0;
		for (this.i = 0; this.i < this.data.length; this.i++) {
			if (this.current != this.data[this.i][0]) {
				this.current = this.data[this.i][0];	
			} else continue;
			if (this.data[this.i][4] > 0)
				this.count++;
		}*/
		for (this.ReturnOpened.i = 1; this.ReturnOpened.i < 100; this.ReturnOpened.i++) {
			this.ReturnOpened.obj = document.getElementById('fernandomenu'+this.ReturnOpened.i);
			if (this.ReturnOpened.obj) {
				if (this.ReturnOpened.obj.style.visibility == 'visible')
					continue;
				return this.ReturnOpened.i;
			} else
				return this.ReturnOpened.i;
		}
		return 0;
	}
	
	this.ClearMenus = function(column) {
		for (this.i = 0; this.i < this.data.length; this.i++) {
			if (this.data[this.i][4] >= column) {
				this.data[this.i][4] = 0;
			}
		}
		this.submenusshown = new Array();
		
		for (this.i = column; this.i <= 100; this.i++) {
			this.ClearMenus.obj = document.getElementById('fernandomenu'+this.i);	
			if (this.ClearMenus.obj) {
				this.ClearMenus.obj.style.visibility = 'hidden';
			} else break;
		}
	}
	
	this.HideWordpress = function(id) {
		this.content = document.getElementById(id);
		if (this.content) {
			this.opacity = 50;
			this.content.style.opacity = this.opacity / 100;
			this.content.style.MozOpacity = this.opacity / 100;
			this.content.style.filter = "alpha(opacity=" + (this.opacity) + ")";	
		}
	}
	
	this.ShowWordpress = function(id) {
		this.content = document.getElementById(id);
		if (this.content) {
			this.opacity = 100;
			this.content.style.opacity = this.opacity / 100;
			this.content.style.MozOpacity = this.opacity / 100;
			this.content.style.filter = "alpha(opacity=" + (this.opacity) + ")";	
			this.content.style.filter = "";	
		}	
	}
	
	this.FindPos = function (obj) {
		this.curleft = this.curtop = 0;
		if (obj.offsetParent) {
			this.curleft = obj.offsetLeft
			this.curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				this.curleft += obj.offsetLeft
				this.curtop += obj.offsetTop
			}
		}
		return [this.curleft,this.curtop];
	}

}

