// menu 1.0.10 - Junciona Object Development, 2001
function menuBar(objName, parent){
  if ((junciona.ns4) && (objName == "menu")) alert("No se puede usar el nombre de 'menu' en Netscape 4")
  eval(objName+" = new menuBar.menu(objName,parent)");
}

menuBar.menu = function(objName,parent){
  this.strObj = this.id = objName;
  this.optActive = null;
  this.optInCurse = null;
  this.lastOptSelec = null;
  this.optSelec = null;
  this.selectedChild = null;
  this.state = "ok";
  if(parent){
    this.parent = parent;
    this.grandParent = eval(this.parent).grandParent;
  }else{
    this.parent = null;
    this.grandParent = this.id;
  }
}

menuBar.menu.prototype.setContainer = function(cont){this.container = cont}

menuBar.menu.prototype.setItems = function(arrOpt){
  this.arrMenuOpt = arrOpt;
  for (var i=0; i<arrOpt.length; i++){
    menuBar(arrOpt[i],this.id);
    eval("mo_"+arrOpt[i]+"= new menuBar.menuItem('"+arrOpt[i]+"',"+this.id+","+this.parent+")");
  }
}

menuBar.menu.prototype.turnOffAllChildren = function(root){
  if (this.selectedChild){
    var a = eval(this.selectedChild).turnOffAllChildren(root);
    if (root != this.id) this.turnOffChild();
    return a;
  }else this.turnOffChild();
}

menuBar.menu.prototype.turnOffChild = function(){
  if (this.optSelec){
    eval("mo_"+this.optSelec).imgOnOff('OFF');
    this.optSelec = null;
    this.selectedChild = null;
  }
  this.hideMenu();
}

menuBar.menuItem = function(objName,box,parent){
  this.strObj = this.id = "mo_"+objName;
  this.parent = (parent==null)?null:parent;
  this.child = objName;
  this.box = box;
}

menuBar.menuItem.prototype.setMouseEvents = function(mdown,mover,mout){
  this.mdownhref = (mdown==null)?this.id+".mgrHref()":mdown;
  if (mover==null){
    this.moverhref = this.id+".mgrRollOver('ON',null)"
  }else{
    this.moverhref = this.id+".mgrRollOver(null,'mover')";
    this.moverhrefAction = mover;
  }
  if (mout==null){
    this.mouthref = this.id+".mgrRollOver('OFF',null)"
  }else{
    this.mouthref = this.id+".mgrRollOver(null,'mout')";
    this.mouthrefAction = mout;
  }
}

menuBar.menuItem.prototype.setProp = function(parent,x,y,w,h,bgCol,vis,zInd,img,imgW,imgH,enlace){
  if (!this.mdownhref) this.setMouseEvents(null,null,null);
  var objName = "moLayer"+this.id;
  var auxCont = "<a href=javascript:"+this.mdownhref+" onmouseover="+this.moverhref+" onmouseout="+this.mouthref+"><img src="+img+((imgW!=null)?" width="+imgW:"")+((imgH!=null)?" height="+imgH:"")+" name="+this.child+"Img id="+this.child+"Img border=0></a>";
  this.menuOptLayer = junciona(objName,parent,x,y,w,h,bgCol,vis,((zInd!=null)?zInd:15), auxCont);
  this.linkRef = enlace;
  this.imgRef = this.child+"Img";
}

menuBar.menuItem.prototype.mgrHref = function(){
  if (eval(this.box.grandParent).state=="ok" && this.box.optSelec != this.child){
    eval(this.box.grandParent).state = "busy";
    var child = eval(this.child);
    this.box.optInCurse = child.id;
    if (this.parent!=null){
      this.parent.selectedChild = this.box.id;
      if ( this.parent.optSelec !=null ){
        eval("mo_"+this.parent.optSelec).imgAction('OFF');
        this.parent.optSelec = null;
      }
    }
  
    if (this.box.optSelec || this.box.selectedChild){
      var finished = this.box.turnOffAllChildren(this.box.id);
      if (this.box.optSelec) eval("mo_"+this.box.optSelec).imgAction("OFF");
    }
  
    if (child.arrMenuOpt) child.showMenu();
    else{
      this.box.optInCurse = this.child;
      this.box.startHiding();
    }
    this.imgAction("ON");
    this.box.optSelec = this.box.optActive = this.box.selectedChild = child.id;
    if ( this.linkRef != null ) this.box.action(this.linkRef);
  }
}

menuBar.menuItem.prototype.mgrRollOver = function(onOff,evento,force){
  if ((eval(this.box).optSelec != this.child) || force==true){
    if (onOff!=null) this.imgAction(onOff);
    else (evento=="mout")?eval(this.mouthrefAction):eval(this.moverhrefAction);
  }
}

menuBar.menuItem.prototype.imgOnOff = function(onOff){
    var img = this.child+"Img";
    var newImg = "img/"+this.child+onOff+".gif";
    if (junciona.ie) document.all[img].src = newImg;
    else if (junciona.ns4) eval(this.menuOptLayer.node).document[img].src = newImg;
    else if (junciona.ns6) document.getElementById(img).src=newImg;
}

menuBar.menuItem.prototype.imgAction = function(onOff){
  (onOff=="ON")?eval(this.moverhref): setTimeout(this.mouthref,10);
}