// ***********************************************************
//
//  Desenvolvido por AG2 - Agencia de Inteligencia Digital SA
//  Todos os direitos reservados
//
//  versao 1.1 (suporte a imagem)
// ***********************************************************


////
///  Manipulacao de Objetos
//

function mocMenu(sLay,sImg,nDelay,nPx,nPy) {
	this.lay	= sLay;
	this.lnk	= sLay+"lnk";
	this.imgN	= (sImg)?sLay+"img":0;
	this.imgU	= sImg;
	this.delay	= nDelay;
	this.posx	= nPx;
	this.posy	= nPy;
	this.status	= 1;

	var oLnk	= new mocLnk(this.lnk,this.lay);
	var oLay	= new mocLay(this.lay,this.lnk,nPx,nPy,this.delay,this.imgN,this.imgU);
	
	oLnk.obj.onmouseover = function() { oLay.setStatus(1); }
	oLnk.obj.onmouseout = function() { oLay.setStatus(0); }
	oLay.obj.onmouseout = function() { oLay.setStatus(0); }
	oLay.obj.onmouseover = function() { oLay.setStatus(1); }
}

function mocLnk(sLnk,sLay) { 
	this.obj	= document.getElementById(sLnk);
	this.objN	= sLnk;
	this.oLay	= document.getElementById(sLay);
	
	with(this.oLay.style) {
		position = "absolute";
		visibility="hidden";
	}
	with(this.obj.style) {
		display="block";
	}
	this.getPy = function() {
		return findPosY(this.obj);
	}
	this.getPx = function() {
		return findPosX(this.obj);
	}
}

function mocLay(sLay,sLnk,nPx,nPy,nDelay,sImgN,sImgU) {
	this.obj	= document.getElementById(sLay);
	this.objN	= sLay;
	this.oLnk	= document.getElementById(sLnk);
	this.nPx	= nPx;
	this.nPy	= nPy;
	this.timer	= 0;
	this.delay	= nDelay;

	this.imgN	= sImgN;
	this.imgU	= sImgU;
	this.imgUx	= (this.imgN)?(document.getElementById(this.imgN))?document.getElementById(this.imgN).src:alert('Objeto "'+this.imgN+'" nao encontrado!'):0;

	this.getPy = function() {
		return findPosY(this.obj);
	}
	this.getPx = function() {
		return findPosX(this.obj);
	}
	
	this.setStatus = function(bVar) {
		this.setPos(); 
		if(bVar) { this.setTimer(0); }
		else { this.setTimer(1); }
	}

	this.getStatus = function() {
		var tmp = this.obj.style.visibility;
		if(tmp=="hidden") return 0; else return 1;
	}

	this.setPos = function() {
		var py = findPosY(this.oLnk);
		var px = findPosX(this.oLnk);
		with(this.obj.style) { top=eval(py+this.nPy)+"px"; left=eval(px+this.nPx)+"px"; }
	}

	this.setTimer = function(bVar) {
		var tmp = this.objN.toString();
  		if(bVar) {
			var tmp2 = (this.imgN)?"mocSetImage('"+this.imgN+"','"+this.imgUx+"')":"";
			this.timer = setTimeout("mocSetHidden('"+this.objN+"');"+tmp2,this.delay); 
		}
		else {
			if(this.timer) clearTimeout(this.timer); 
			this.obj.style.visibility = "visible";  
			if(this.imgN) mocSetImage(this.imgN,this.imgU) 
		}
	}
}

function mocSetHidden(sObjName) {
	document.getElementById(sObjName).style.visibility="hidden";
}
function mocSetImage(sImgN,sImgU) {
	document.getElementById(sImgN).src=sImgU;
}

////
/// 	L I B R A R Y
//

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	window.status = printstring;
	return curtop;
}

function getObj(name) {
  if (document.getElementById)  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all) {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers) {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

function getObjNN4(obj,name) {
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++) {
		if (x[i].id == name)
			foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

