//------------------------------------------------------------------------------
// DomAPI MenuBar Component
// D. Kadrioski 10/05/2001
// (c) Nebiru Software 2001
//------------------------------------------------------------------------------
function MenuBar(parent,theme,x,y,w,h){
  var elm       = createElm(parent,x||0,y||0,w||450,h||26);
  elm.theme     = theme?theme:defaultTheme;
  elm.isOpened  = false;
  with(elm.style){
    cursor      = "default";
    margin      = "0px";
    padding     = "0px";
    fontFamily  = '"MS Sans Serif",Geneva,sans-serif';
    fontSize    = "8pt";
    padding     = "2px 0px";
    overflow    = "visible";
    listStyle   = "none";
    height      = "auto";
    backgroundColor  = "blue";
  }
  //----------------------------------------------
  elm.addItem = function(caption,fn){
    this.appendChild(MenuItem(this,caption,fn));
    with(this.childNodes[this.childNodes.length-1]){
      isOpened=false;
      style.padding="1px 5px";
    }
    return this.childNodes[this.childNodes.length-1];
  };
  //----------------------------------------------
  elm.onmouseover=function(e){
    var temp=findTarget(e,"MENUITEM"); if(!temp)return;
    with(temp.style){
      color           = this.theme.selFgColor;
      backgroundColor = this.theme.selBgColor;
      font            = this.theme.selFont;
    }
    if(this.isOpened)
      if(temp.dropDown){
        temp.dropDown.style.font = this.theme.ctrlFont;
        if(temp.dropDown.visible())return;
        this.hideAllMenus();
        temp.dropDown.moveTo(parseInt(temp.offsetLeft),parseInt(this.offsetHeight)-2);
        temp.dropDown.show();
        temp.isOpened=true;
        this.isOpened=true;
      }
  };
  //----------------------------------------------
  elm.onmouseout=function(e){
    var temp=findTarget(e,"MENUITEM"); if(!temp)return;
    with(temp.style){
      color           = this.theme.ctrlFgColor;
      backgroundColor = this.theme.ctrlBgColor;
      font            = this.theme.ctrlFont;
    }
  };
  //----------------------------------------------
  elm.onclick=function(e){
    var temp=findTarget(e,"MENUITEM"); if(!temp)return;
    if(temp.isOpened)
      this.hideAllMenus();
    else{
      this.hideAllMenus();
      if(temp.dropDown){
        temp.dropDown.moveTo(parseInt(temp.offsetLeft),parseInt(this.offsetHeight)-2);
        temp.dropDown.show();
      }
      if(temp.dropDown)temp.dropDown.style.font = this.theme.ctrlFont;
      temp.isOpened=true;
      this.isOpened=true;
    }
  };
  //----------------------------------------------
  elm.hideAllMenus=function(){
    for(var a=0;a<this.childNodes.length;a++){
      if(this.childNodes[a].dropDown)this.childNodes[a].dropDown.hide();
      this.childNodes[a].isOpened=false;
    }
    this.isOpened=false;
  };
  //----------------------------------------------
  elm.reDraw=function(){
    with(this.style){
      backgroundColor = this.theme.ctrlBgColor;
      color           = this.theme.ctrlFgColor;
      borderStyle     = this.theme.bdrOutset;
      borderWidth     = this.theme.bdrWidth;
      borderColor     = this.theme.bdrColor;
    }
    for(var b=0;b<this.childNodes.length;b++){
      with(this.childNodes[b].style){
        backgroundColor = this.theme.ctrlBgColor;
        color           = this.theme.ctrlFgColor;
      }
      if(this.childNodes[b].dropDown){
        this.childNodes[b].dropDown.theme=this.theme;
        this.childNodes[b].dropDown.reDraw();
      }
    }
  };
  //-----
  elm.reDraw();
  elm.domAPIObjType="MENUBAR";
  return elm;
};
//------------------------------------------------------------------------------