/*********************************************************/
/*                 Funções auxiliares                    */
/*********************************************************/

//Retorna o top de um objeto
function getTop(id) {
	var curtop = 0;
	var obj = document.getElementById(id);
	if (obj != null) {
		if (obj.offsetParent) {
			do {
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
	}
	return curtop;
}

//Retorna o left de um objeto
function getLeft(id) {
	var curleft = 0;
	var obj = document.getElementById(id);
	if (obj != null) {
		curleft = obj.offsetLeft;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
			} while (obj = obj.offsetParent);
		}
	}
	return curleft;
}

/*********************************************************/
/*                    Classe MENU                        */
/*********************************************************/

function PosicionaDiv(div,width,height,top,left) {
	var m = document.getElementById(div);	
	if (m != null) {
		m.style.top = top + "px";
		m.style.left = left + "px";
		m.style.width = width + "px";
		m.style.height = height + "px";
	}
}

function SetVisibleMenu() {
	var m = document.getElementById(this.div_menu);
	if (m != null) {
		if (this.exibe) {
			PosicionaDiv(this.div_menu,this.width,this.height,this.top,this.left);
			m.style.display = "block";
		} else {
			m.style.display = "none";
		}
	}
	var m = document.getElementById(this.div_sombra);
	if (m != null) {
		if (this.exibe) {
			PosicionaDiv(this.div_sombra,this.width,this.height,this.top+2,this.left+2);
			m.style.display = "block";
			this.exibe = false;
		} else {
			m.style.display = "none";
			this.exibe = true;
		}
	}
	this.ultimo_link = true;
}

function EscondeMenu() {
	var m = document.getElementById(this.div_menu);
	if (m != null) {
		m.style.display = "none";
	}
	var m = document.getElementById(this.div_sombra);
	if (m != null) {
		m.style.display = "none";
	}
	if (!this.ultimo_link) {
		this.exibe = true;
	}
	this.ultimo_link = false;
}

function ClasseMenu(div_menu,div_sombra,width,height,top,left) {
	this.exibe = true;
	this.ultimo_link = false;
	this.div_menu = div_menu;
	this.div_sombra = div_sombra;
	this.width = width;
	this.height = height;
	this.top = top;
	this.left = left;	
	//Chamar no evento OnClick do body
	this.EsconderMenu = EscondeMenu;
	//Chamar no click no link que exibirá o menu
	this.SetarVisible = SetVisibleMenu;
}
