// ***********************************************************
//
//  Desenvolvido por AG2 - Agencia de Inteligencia Digital SA
//  Todos os direitos reservados
//
//  versao 1.0
// ***********************************************************

///  Manipulacao de Objetos


function mocMenu(sLay, sLnk, nDelay, nPx, nPy) {
   this.lay = sLay; // nome da div
   this.lnk = sLnk; // nome do link
   this.delay = nDelay;
   this.posx = nPx;
   this.posy = nPy;
   this.status = 1; // 1 - show / 2 - hide

   var oLnk = new mocLnk(this.lnk, this.lay);
   var oLay = new mocLay(this.lay, this.lnk, nPx, nPy, this.delay);

   oLnk.obj.onmouseover = function() { oLay.setStatus(1); }
   oLnk.obj.onmouseout = function() { oLay.setStatus(0); }
   oLnk.obj.onfocus = function() { oLay.setStatus(1); }
   oLnk.obj.onblur = function() {
   //alert(this.parentNode.id.indexOf("submenu"));
      if (this.parentNode.id.indexOf("submenu") < 0 && event.shiftKey) {
         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);

   this.oLay.style.position = "absolute";
   this.oLay.style.visibility = "hidden";
   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) {
   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.getPy = function() {
      return findPosY(this.obj);
   }
   this.getPx = function() {
      return findPosX(this.obj);
   }

   // ## configura visilibidade
   this.setStatus = function(bVar) {
      this.setPos();
      if (bVar) { this.setTimer(0); }
      else { this.setTimer(1); }
   }
   // ## captura visibilidade
   this.getStatus = function() {
      var tmp = this.obj.style.visibility;
      if (tmp == "hidden") return 0; else return 1;
   }
   // ## configura posicao
   this.setPos = function() {
      var py = findPosY(this.oLnk);
      var px = findPosX(this.oLnk);
      //alert(py+" "+px);
      with (this.obj.style) { top = eval(py + this.nPy) + "px"; left = eval(px + this.nPx) + "px"; }
   }
   // ## configura temporizador
   this.setTimer = function(bVar) {
      var tmp = this.objN.toString();
      if (bVar) { this.timer = setTimeout("setHidden('" + this.objN + "')", this.delay) }
      else { if (this.timer) clearTimeout(this.timer); this.obj.style.visibility = "visible"; }
   }
}

function setHidden(sObjName) {
   document.getElementById(sObjName).style.visibility = "hidden";
}

////
/// 	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;
}


 