
/*
Get the left position of the menu bar menu.
*/
function getMainMenuBarMenuLeftPos(menuBarObj, menuBarItemObj, menuObj, x) { // Private method
  if (x + menuObj.offsetWidth <= getClientWidth()) {
    return x;
  }
  else {
    var pos = x + menuBarItemObj.offsetWidth - menuObj.offsetWidth + getPropIntVal(menuObj, "border-left-width") + getPropIntVal(menuObj, "border-right-width");
    return pos < 0 ? 0 : pos;
  }
};

/*
Get the top position of the menu bar menu.
*/
function getMainMenuBarMenuTopPos(menuBarObj, menuBarItemObj, menuObj, y) { // Private method
  if (y + menuObj.offsetHeight <= getClientHeight()) {
    return y;
  }
  else {
    var pos = y - menuObj.offsetHeight - menuBarObj.offsetHeight;
    return pos < 0 ? 0 : pos;
  }
};

/*
Pop up the menu bar menu.
*/
function popUpMenuBarMenu(menuBarObj, menuBarItemObj, menuObj) { // Private method
  var x;
  var y;
  if (menuBarObj.style.position == "fixed") {
    x = menuBarObj.offsetLeft + menuBarItemObj.offsetLeft + getPropIntVal(menuBarObj, "border-left-width") - getPropIntVal(menuObj, "border-left-width");
    y = menuBarObj.offsetTop + menuBarObj.offsetHeight;
    if (opera || safari) {
      x -= getPropIntVal(menuBarObj, "border-left-width");
    }
    menuObj.style.position = "absolute";
    menuObj.style.left = getMainMenuBarMenuLeftPos(menuBarObj, menuBarItemObj, menuObj, x) + "px";
    menuObj.style.top = getMainMenuBarMenuTopPos(menuBarObj, menuBarItemObj, menuObj, y) + "px";
    menuObj.style.position = "fixed";
  }
  else {
    if (menuBarObj.mode == "static") {
        x = getLeft(menuBarItemObj) - getPropIntVal(menuObj, "border-left-width") - getScrollLeft();
        y = getTop(menuBarObj) + menuBarObj.offsetHeight - getScrollTop();
      if (ie55 || ie6) {
        x += getPropIntVal(menuBarObj, "border-left-width");
        y = getTop(menuBarItemObj) + menuBarItemObj.offsetHeight + getPropIntVal(menuBarObj, "border-top-width") + getPropIntVal(menuBarObj, "border-bottom-width") - getScrollTop();
      }
      menuObj.style.left = (getMainMenuBarMenuLeftPos(menuBarObj, menuBarItemObj, menuObj, x) + getScrollLeft()) + "px";
      menuObj.style.top = (getMainMenuBarMenuTopPos(menuBarObj, menuBarItemObj, menuObj, y) + getScrollTop()) + "px";
    }
    else {
      x = menuBarObj.offsetLeft + menuBarItemObj.offsetLeft + getPropIntVal(menuBarObj, "border-left-width") - getPropIntVal(menuObj, "border-left-width") - getScrollLeft();
      y = menuBarObj.offsetTop + menuBarObj.offsetHeight - getScrollTop();
      if (opera || safari) {
        x -= getPropIntVal(menuBarObj, "border-left-width");
      }
      menuObj.style.left = (getMainMenuBarMenuLeftPos(menuBarObj, menuBarItemObj, menuObj, x) + getScrollLeft()) + "px";
      menuObj.style.top = (getMainMenuBarMenuTopPos(menuBarObj, menuBarItemObj, menuObj, y) + getScrollTop()) + "px";
    }
  }
  if (ie && menuObj.mode == "fixed") {
    menuObj.initialLeft = parseInt(menuObj.style.left) - getScrollLeft();
    menuObj.initialTop = parseInt(menuObj.style.top) - getScrollTop();
  }
  menuObj.style.visibility = "visible";
};

/*
Deactivate the menu bar items.
*/
function deactivateMenuBarItems(menuBarObj) { // Private method
  var i = menuBarObj.childNodes.length - 1;
  if (i > -1) {
    do {
      if (menuBarObj.childNodes[i].enabled && menuBarObj.childNodes[i].clicked) {
        menuBarObj.childNodes[i].className = menuBarObj.childNodes[i].itemClassName;
        if (menuBarObj.childNodes[i].iconObj) {
          menuBarObj.childNodes[i].iconObj.className = menuBarObj.childNodes[i].iconClassName;
        }
        menuBarObj.childNodes[i].clicked = false;
        if (menuBarObj.childNodes[i].menu) {
          hideMenus(menuBarObj.childNodes[i].menu.menuObj);
        }
        break;
      }
    } while (i--);
  }
  menuBarObj.activated = false;
};

/*
Event handler that handles onmouseover event of the menu bar item.
*/
function menuBarItemOver(e) { // Private method
  if (intervalId) {
    clearTimeout(intervalId);
  }
  if (this.parent.menuBarObj.activated) {
    if (!this.clicked) {
      var menuBarObj = this.parent.menuBarObj;
      var i = menuBarObj.childNodes.length - 1;
      if (i > -1) {
        do {
          if (menuBarObj.childNodes[i].enabled && menuBarObj.childNodes[i].clicked) {
            menuBarObj.childNodes[i].className = menuBarObj.childNodes[i].itemClassName;
            if (menuBarObj.childNodes[i].iconObj) {
              menuBarObj.childNodes[i].iconObj.className = menuBarObj.childNodes[i].iconClassName;
            }
            menuBarObj.childNodes[i].clicked = false;
            if (menuBarObj.childNodes[i].menu) {
              hideMenus(menuBarObj.childNodes[i].menu.menuObj);
            }
            break;
          }
        } while (i--);
      }
      if (this.enabled) {
        if (this.menu) {
          this.onclick(e);
        }
        else {
          if (this.href) {
            this.className = this.itemClassNameClick;
            if (this.iconObj && this.iconClassNameClick) {
              this.iconObj.className = this.iconClassNameClick;
            }
            this.clicked = true;
          }
        }
      }
    }
  }
  else {
    var menuBarObj = this.parent.menuBarObj;
    var i = menuBarObj.childNodes.length - 1;
    if (i > -1) {
      do {
        if (menuBarObj.childNodes[i].enabled) {
          menuBarObj.childNodes[i].className = menuBarObj.childNodes[i].itemClassName;
          if (menuBarObj.childNodes[i].iconObj) {
            menuBarObj.childNodes[i].iconObj.className = menuBarObj.childNodes[i].iconClassName;
          }
        }
      } while (i--);
    }
    if (this.enabled && (this.menu || this.href)) {
      switch (menuBarObj.activateMode) {
        case "click":
          this.className = this.itemClassNameOver;
          break;
        case "over":
          if (this.menu) {
            this.onclick(e);
          }
          else {
            this.className = this.itemClassNameOver;
          }
          break;
      }
      if (this.iconObj && this.iconClassNameOver) {
        this.iconObj.className = this.iconClassNameOver;
      }
    }
  }
};

/*
Event handler that handles onclick event of the menu bar item.
*/
function menuBarItemClick(e) { // Private method
	if (!e) {
    var e = window.event;
  }
  var targetElm = e.target || e.srcElement;
  if (this.enabled) {
		if (this.clicked) {
			if (this.action) {
				eval(this.action);
			}
			if (this.href && targetElm.tagName != "A") {
				location.href = this.href;
			}
		}
    if (this.menu) {
      if (this.clicked) {
        this.className = this.itemClassNameOver;
        if (this.iconObj) {
          this.iconObj.className = this.iconClassNameOver;
        }
        hideMenus(this.menu.menuObj);
        this.clicked = false;
        this.parent.menuBarObj.activated = false;
      }
      else {
        this.className = this.itemClassNameClick;
        if (this.iconObj && this.iconClassNameClick) {
          this.iconObj.className = this.iconClassNameClick;
        }
        popUpMenuBarMenu(this.parent.menuBarObj, this, this.menu.menuObj);
        this.clicked = true;
        this.parent.menuBarObj.activated = true;
      }
    }
    else {
			var clicked = false;
			if (this.action) {
				eval(this.action);
				clicked = true;
			}
      if (this.href && targetElm.tagName != "A") {
				location.href = this.href;
				clicked = true;
      }
			if (clicked) {
				this.className = this.itemClassName;
				if (this.iconObj) {
					this.iconObj.className = this.iconClassName;
				}
				this.clicked = false;
				this.parent.menuBarObj.activated = false;
			}
    }
  }
  if (ie) {
    e.cancelBubble = true;
  }
  if (e.stopPropagation) {
    e.stopPropagation();
  }
	if (!this.href || this.clicked) {
		return false;
	}
};

/*
Event handler that handles onmouseout event of the menu bar item.
*/
function menuBarItemOut() { // Private method
  intervalId = setTimeout("deactivate()", autoHideTimeLimit);
  if (!this.parent.menuBarObj.activated) {
    this.className = this.itemClassName;
    if (this.iconObj) {
      this.iconObj.className = this.iconClassName;
    }
  }
};

/*
Event handler that handles onmousedown event of the menu bar.
*/
function menuBarDown(e) { // Private method
  draggingObj = this.parent.menuBarObj;
  var menuBarObj = this.parent.menuBarObj;
  menuBarObj.differenceLeft = getX(e) - menuBarObj.offsetLeft;
  menuBarObj.differenceTop = getY(e) - menuBarObj.offsetTop;
  hideMenuBarMenus();
  document.onmousemove = mouseMoveHandler;
};

/*
Event handler that handles onmouseup event of the menu bar.
*/
function menuBarUp() { // Private method
  draggingObj = null;
  var menuBarObj = this.parent.menuBarObj;
  menuBarObj.differenceLeft = 0;
  menuBarObj.differenceTop = 0;
  menuBarObj.initialLeft = menuBarObj.offsetLeft - getScrollLeft();
  menuBarObj.initialTop = menuBarObj.offsetTop - getScrollTop();
  document.onmousemove = null;
};

/*
Event handler that handles mouse move event.
*/
function mouseMoveHandler(e) { // Private method
  if (draggingObj) {
    draggingObj.style.left = (getX(e) - draggingObj.differenceLeft) + "px";
    draggingObj.style.top = (getY(e) - draggingObj.differenceTop) + "px";
  }
};

/*
Event handler that handles scroll event.
*/
function menuBarScrollHandler() { // Private method
  var i = menuBarCount;
  do {
    var menuBarObj = getElmId("DOMenuBar" + i);
    if (menuBarObj.mode == "fixed") {
      menuBarObj.style.left = (menuBarObj.initialLeft + getScrollLeft()) + "px";
      menuBarObj.style.top = (menuBarObj.initialTop + getScrollTop()) + "px";
    }
  } while (--i);
};

/*
Remove all menu bars events.
*/
function removeMenuBarEvents(menuBarObj) { // Private method
  var fields = new Array("setMode", 
                         "setActivateMode", 
                         "setDraggable", 
                         "setClassName", 
                         "setDragClassName", 
                         "show", 
                         "hide", 
                         "setX", 
                         "setY", 
                         "moveTo", 
                         "moveBy", 
                         "setBorderWidth");
  var i = fields.length - 1;
  do {
    menuBarObj[fields[i]] = null;
  } while (i--);
};

/*
Release the memory to minimize memory leak.
*/
function menuBarReleaseMemory() { // Private method
  var i = menuBarCount;
  var menuBarObj;
  if (i > 0) {
    do {
      menuBarObj = getElmId("DOMenuBar" + i);
      removeMenuBarEvents(menuBarObj.parent);
      removeItemEvents(menuBarObj);
      menuBarObj.parent.dragObj.parent = null;
      menuBarObj.parent = null;
      menuBarObj.onclick = null;
      document.body.removeChild(menuBarObj);
    } while (--i);
  }
  i = staticMenuBarId.length - 1;
  if (i > -1) {
    do {
      menuBarObj = getElmId(staticMenuBarId[i]);
      removeMenuBarEvents(menuBarObj.parent);
      removeItemEvents(menuBarObj);
      menuBarObj.parent.dragObj.parent = null;
      menuBarObj.parent = null;
      menuBarObj.onclick = null;
    } while (i--);
  }
};

/*
Hide all menu bar menus.
*/
function hideMenuBarMenus() { // Public method
  var i = menuBarCount;
  if (i > 0) {
    do {
      deactivateMenuBarItems(getElmId("DOMenuBar" + i));
    } while (--i);
  }
};

/*
Show the icon before the display text.
Arguments:
className          : Required. String that specifies the CSS class selector for the icon.
classNameOver      : Optional. String that specifies the CSS class selector for the icon when 
                     the cursor is over the menu bar item.
classNameClick     : Optional. String that specifies the CSS class selector for the icon when 
                     the cursor is clicked on the menu bar item.
*/
function showMenuBarItemIcon() { // Public method
  var iconElm = createElm("span");
  var textNode = document.createTextNode("");
  iconElm.appendChild(textNode);
  iconElm.id = this.id + "Icon";
  iconElm.className = arguments[0];
  this.insertBefore(iconElm, this.firstChild);
  var height;
  var offsetHeight;
  var menuBarObj = this.parent.menuBarObj;
  var offset = getPropIntVal(menuBarObj, "border-top-width") 
             + getPropIntVal(this, pt) 
             - getPropIntVal(menuBarObj, pb) 
             - getPropIntVal(menuBarObj, "border-bottom-width") 
             - getPropIntVal(this, pb);
  iconElm.style.top = Math.floor((this.offsetHeight - iconElm.offsetHeight) / 2) + "px";
  if (opera && this.parent.menuBarObj.mode != "static") {
    iconElm.style.display = "none";
  }
  this.iconClassName = iconElm.className;
  var l = arguments.length;
  if (l > 1 && arguments[1].length > 0) {
    this.iconClassNameOver = arguments[1];
  }
  if (l > 2 && arguments[2].length > 0) {
    this.iconClassNameClick = arguments[2];
  }
  this.iconObj = iconElm;
  /*
  Set the class name of the icon.
  Argument:
  className          : Required. String that specifies the CSS class selector for the icon.
  */
  this.setIconClassName = function(className) { // Public method
    if (opera && this.parent.menuBarObj.mode != "static") {
      return;
    }
    this.iconClassName = className;
    this.iconObj.className = this.iconClassName;
  };
  /*
  Set the class name of the icon when the cursor is over the menu bar item object.
  Argument:
  classNameOver      : Required. String that specifies the CSS class selector for the icon when the 
                       cursor is over the menu bar item object.
  */
  this.setIconClassNameOver = function(classNameOver) { // Public method
    if (opera && this.parent.menuBarObj.mode != "static") {
      return;
    }
    this.iconClassNameOver = classNameOver;
  };
  /*
  Set the class name of the icon when the cursor is clicked on the menu bar item object.
  Argument:
  classNameClick     : Required. String that specifies the CSS class selector for the icon when the 
                       cursor is clicked on the menu bar item object.
  */
  this.setIconClassNameClick = function(classNameClick) { // Public method
    if (opera && this.parent.menuBarObj.mode != "static") {
      return;
    }
    this.iconClassNameClick = classNameClick;
  };
  iconElm = null;
};

/*
Add a new menu bar item to the menu bar.
Argument:
menuBarItemObj     : Required. Menu bar item object that is going to be added to the menu bar 
                     object.
*/
function addMenuBarItem(menuBarItemObj) { // Public method
  var itemElm = createElm("span");
  itemElm.id = menuBarItemObj.id;
  itemElm.menu = menuBarItemObj.menu;
  itemElm.enabled = menuBarItemObj.enabled;
  itemElm.clicked = false;
  itemElm.href = menuBarItemObj.href;
	itemElm.action = "";
  itemElm.itemClassName = menuBarItemObj.className;
  itemElm.itemClassNameOver = menuBarItemObj.classNameOver;
  itemElm.itemClassNameClick = menuBarItemObj.classNameClick;
  itemElm.className = itemElm.itemClassName;
  if (ie50) {
    itemElm.style.height = "1%";
  }
  if (ie55) {
    itemElm.style.width = "auto";
  }
	var text = menuBarItemObj.displayText;
  var textElm;
	if (typeof(text) == "string") {
		if (typeof(itemElm.innerHTML) != "undefined") {
			textElm = createElm("a");
			if (itemElm.href) {
				textElm.setAttribute("href", itemElm.href);
			}
			textElm.innerHTML = text;
		}
		else {
			textElm = document.createTextNode(text);
		}
  }
	else {
		textElm = text;
	}
  itemElm.appendChild(textElm);
  this.menuBarObj.appendChild(itemElm);
  itemElm.parent = this;
  /*
  Set the class name of the menu bar item object.
  Argument:
  className          : Required. String that specifies the CSS class selector for the menu bar item 
                       object.
  */
  itemElm.setClassName = function(className) { // Public method
    this.itemClassName = className;
    this.className = this.itemClassName;
  };
  /*
  Set the class name of the menu bar item object when the cursor is over it.
  Argument:
  classNameOver      : Required. String that specifies the CSS class selector for the menu bar item 
                       object when the cursor is over it.
  */
  itemElm.setClassNameOver = function(classNameOver) { // Public method
    this.itemClassNameOver = classNameOver;
  };
  /*
  Set the class name of the menu bar item object when the cursor is clicked on it.
  Argument:
  classNameClick     : Required. String that specifies the CSS class selector for the menu bar item 
                       object when the cursor is clicked on it.
  */
  itemElm.setClassNameClick = function(classNameClick) { // Public method
    this.itemClassNameClick = classNameClick;
  };
  /*
  Set the display text of the menu bar item object.
  Argument:
  displayText        : Required. String that specifies the text to be displayed on the menu bar item 
                       object. It can contain HTML tags.
  */
  itemElm.setDisplayText = function(displayText) { // Public method
    var index = this.childNodes[0].id.indexOf("Icon") > -1 ? 1 : 0;
    var node = this.childNodes[index];
    if (typeof(node.innerHTML != "undefined")) {
      node.innerHTML = displayText;
    }
    else {
      node.nodeValue = displayText;
    }
  };
  /*
  Set the hypertext reference to be loaded when the menu bar item object is being clicked.
  Argument:
  href               : Required. String that specifies the hypertext reference to be loaded when the 
                       menu bar item object is being clicked.
  */
	itemElm.setHref = function(href) { // Public method
		this.href = href;
		var index = this.childNodes[0].id.indexOf("Icon") > -1 ? 1 : 0;
		var node = this.childNodes[index];
		node.setAttribute("href", href);
	};
  /*
  Set the action to be taken when the menu bar item object is being clicked.
  Argument:
  action             : Required. String that specifies the action to be taken when the menu bar item 
                       object is being clicked.
  */
  itemElm.setAction = function(action) { // Public method
		this.action = action;
	};
  /*
  Set the accesskey that will activate the link for the menu bar item object.
  Argument:
  accessKey          : Required. Character that specifies the accesskey that will activate the link 
                       for the menu bar item object.
  */
	itemElm.setAccessKey = function(accessKey) { // Public method
		var index = this.childNodes[0].id.indexOf("Icon") > -1 ? 1 : 0;
		var node = this.childNodes[index];
		var attr = ie ? "accessKey" : "accesskey";
		if (accessKey) {
			node.setAttribute(attr, accessKey);
		}
		else {
			if (node.removeAttribute) {
				node.removeAttribute(attr);
			}
		}
	}
  /*
  Set the main menu object for the menu bar item object.
  Argument:
  menu               : Required. Menu object that specifies the main menu object for the menu bar item 
                       object.
  */
  itemElm.setMenu = function(menu) { // Public method
    this.menu = menu;
  };
  itemElm.showIcon = showMenuBarItemIcon;
  itemElm.onmouseover = menuBarItemOver;
  itemElm.onclick = menuBarItemClick;
  itemElm.onmouseout = menuBarItemOut;
  if (menuBarItemObj.itemName.length > 0) {
    this.items[menuBarItemObj.itemName] = itemElm;
  }
  else {
    this.items[this.items.length] = itemElm;
  }
  var l = 0;
  for (var x in this.items) {
    ++l;
  }
  if (l == 1 && opera && renderMode == 0) {
    this.dragObj.style.height = (this.dragObj.offsetTop - itemElm.offsetTop) + "px";
  }
  textElm = null;
  itemElm = null;
};

/*
Create a new menu bar item object.
Arguments:
displayText        : Required. String that specifies the text to be displayed on the menu bar item.
menuObj            : Optional. Menu object that is going to be the main menu for the menu bar item. 
                     Defaults to null (no menu).
itemName           : Optional. String that specifies the name of the menu bar item. Defaults to "" 
                     (no name).
enabled            : Optional. Boolean that specifies whether the menu bar item is enabled/disabled. 
                     Defaults to true.
href               : Optional. String that specifies the hypertext reference to be loaded when the 
                     menu bar item is being clicked. Defaults to "" (no reference loaded).
className          : Optional. String that specifies the CSS class selector for the menu bar item. 
                     Defaults to "jsdomenubaritem".
classNameOver      : Optional. String that specifies the CSS class selector for the menu item when 
                     the cursor is over it. Defaults to "jsdomenubaritemover".
classNameClick     : Optional. String that specifies the CSS class selector for the menu item when 
                     the cursor is clicked on it. Defaults to "jsdomenubaritemclick".
*/
function menuBarItem() { // Public method
  this.displayText = arguments[0];
  this.id = "menuBarItem" + (++menuBarItemCount);
  this.itemName = "";
  this.menu = null;
  this.enabled = true;
  this.href = "";
  this.className = menuBarItemClassName;
  this.classNameOver = menuBarItemClassNameOver;
  this.classNameClick = menuBarItemClassNameClick;
  var l = arguments.length;
  if (l > 1 && typeof(arguments[1]) == "object") {
    this.menu = arguments[1];
  }
  if (l > 2 && arguments[2].length > 0) {
    this.itemName = arguments[2];
  }
  if (l > 3 && typeof(arguments[3]) == "boolean") {
    this.enabled = arguments[3];
  }
  if (l > 4 && arguments[4].length > 0) {
    this.href = arguments[4];
  }
  if (l > 5 && arguments[5].length > 0) {
    this.className = arguments[5];
  }
  if (l > 6 && arguments[6].length > 0) {
    this.classNameOver = arguments[6];
  }
  if (l > 7 && arguments[7].length > 0) {
    this.classNameClick = arguments[7];
  }
};

/*
Create a new menu bar object.
Arguments:
mode               : Optional. String that specifies the mode of the menu bar object. Defaults to 
                     "absolute".
id                 : Optional, except when mode = "static". String that specifies the id of 
                     the element that will contain the menu bar object. This argument is required when 
                     mode = "static".
draggable          : Optional. Boolean that specifies whether the menu bar object is draggable. 
                     Defaults to false.
className          : Optional. String that specifies the CSS class selector for the menu bar object. 
                     Defaults to "jsdomenubardiv".
width              : Optional. Integer that specifies the width of the menu bar object. Defaults to 
                     "auto".
height             : Optional. Integer that specifies the height of the menu bar object. Defaults to 
                     "auto".
*/
function jsDOMenuBar() { // Public method
  this.items = new Array();
  var dragElm = createElm("span");
  dragElm.className = menuBarDragClassName;
  var textNode = document.createTextNode("");
  dragElm.appendChild(textNode);
  var menuBarElm;
  var l = arguments.length;
  if (l > 1 && arguments[1].length > 0 && arguments[0] == "static") {
    menuBarElm = getElmId(arguments[1]);
    if (!menuBarElm) {
      return;
    }
    staticMenuBarId[staticMenuBarId.length] = arguments[1];
    menuBarElm.appendChild(dragElm);
  }
  else {
    menuBarElm = createElm("div");
    menuBarElm.appendChild(dragElm);
    menuBarElm.id = "DOMenuBar" + (++menuBarCount);
  }
  menuBarElm.mode = menuBarMode;
  menuBarElm.activateMode = menuBarActivateMode;
  menuBarElm.draggable = false;
  menuBarElm.className = menuBarClassName;
  menuBarElm.activated = false;
  menuBarElm.initialLeft = 0;
  menuBarElm.initialTop = 0;
  menuBarElm.differenceLeft = 0;
  menuBarElm.differenceTop = 0;
  if (l > 0 && arguments[0].length > 0) {
    switch (arguments[0]) {
      case "absolute":
        menuBarElm.style.position = "absolute";
        menuBarElm.mode = "absolute";
        break;
      case "fixed":
        if (ie) {
          menuBarElm.style.position = "absolute";
        }
        else {
          menuBarElm.style.position = "fixed";
        }
        menuBarElm.mode = "fixed";
        break;
      case "static":
        menuBarElm.style.position = "static";
        menuBarElm.mode = "static";
        break;
    }
  }
  if (l > 2 && typeof(arguments[2]) == "boolean") {
    menuBarElm.draggable = arguments[2];
    if (menuBarElm.draggable) {
      dragElm.style.visibility = "visible";
    }
    else {
      dragElm.style.visibility = "hidden";
    }
  }
  if (l > 3 && arguments[3].length > 0) {
    menuBarElm.className = arguments[3];
  }
  if (l > 4 && typeof(arguments[4]) == "number" && arguments[4] > 0) {
    menuBarElm.style.width = arguments[4] + "px";
  }
  if (l > 5 && typeof(arguments[5]) == "number" && arguments[5] > 0) {
    menuBarElm.style.height = arguments[5] + "px";
  }
  menuBarElm.style.left = "0";
  menuBarElm.style.top = "0";
  if (ie50) {
    menuBarElm.style.height = "1%";
  }
  if (menuBarElm.mode != "static") {
    document.body.appendChild(menuBarElm);
  }
  else {
    if (ie) {
      menuBarElm.style.height = "1%";
    }
  }
  if (!getPropVal(menuBarElm, "border-left-width")) {
    menuBarElm.style.borderWidth = menuBarBorderWidth + "px";
  }
  this.menuBarObj = menuBarElm;
  this.menuBarObj.parent = this;
  this.dragObj = dragElm;
  this.dragObj.parent = this;
  this.addMenuBarItem = addMenuBarItem;
  this.menuBarObj.onclick = function(e) { // Private method
    if (!e) {
      var e = window.event;
      e.cancelBubble = true;
    }
    if (e.stopPropagation) {
      e.stopPropagation();
    }
  };
  dragElm.onmousedown = menuBarDown;
  dragElm.onmouseup = menuBarUp;
  /*
  Set the mode of the menu bar object.
  Argument:
  mode               : Required. String that specifies the mode of the menu bar object. Allowed values 
                       are "absolute" and "fixed".
  */
  this.setMode = function(mode) { // Public method
    switch (mode) {
      case "absolute":
        this.menuBarObj.style.position = "absolute";
        this.menuBarObj.mode = "absolute";
        this.menuBarObj.initialLeft = parseInt(this.menuBarObj.style.left);
        this.menuBarObj.initialTop = parseInt(this.menuBarObj.style.top);
        break;
      case "fixed":
        if (ie) {
          this.menuBarObj.style.position = "absolute";
          this.menuBarObj.initialLeft = parseInt(this.menuBarObj.style.left);
          this.menuBarObj.initialTop = parseInt(this.menuBarObj.style.top);
        }
        else {
          this.menuBarObj.style.position = "fixed";
        }
        this.menuBarObj.mode = "fixed";
        break;
    }
  };
  /*
  Set the activate mode of the menu bar.
  Argument:
  activateMode       : Required. String that specifies the activate mode of the menu bar. Allowed 
                       values are "click" and "over".
  */
  this.setActivateMode = function(activateMode) { // Public method
    this.menuBarObj.activateMode = activateMode;
  };
  /*
  Set whether the menu bar object is draggable.
  Argument:
  draggable          : Required. Boolean that specifies whether the menu bar is draggable. If set to 
                       true, you can position the cursor to the dragging region (the leftmost region of 
                       the menu bar) to drag it.
  */
  this.setDraggable = function(draggable) { // Public method
    if (typeof(draggable) == "boolean" && this.menuBarObj.mode != "static") {
      this.menuBarObj.draggable = draggable;
      if (this.menuBarObj.draggable) {
        this.dragObj.style.visibility = "visible";
      }
      else {
        this.dragObj.style.visibility = "hidden";
      }
    }
  };
  /*
  Set the class name of the menu bar object.
  Argument:
  className          : Required. String that specifies the CSS class selector for the menu bar object.
  */
  this.setClassName = function(className) { // Public method
    this.menuBarObj.className = className;
  };
  /*
  Set the class name of the dragging region of the menu bar object.
  Argument:
  className          : Required. String that specifies the CSS class selector for the dragging region 
                       of the menu bar object.
  */
  this.setDragClassName = function(className) { // Public method
    this.dragObj.className = className;
  };
  /*
  Show the menu bar object.
  Argument:
  None.
  */
  this.show = function() { // Public method
    this.menuBarObj.style.visibility = "visible";
  };
  /*
  Hide the menu bar object.
  Argument:
  None.
  */
  this.hide = function() { // Public method
    this.menuBarObj.style.visibility = "hidden";
  };
  /*
  Set the x-coordinate of the menu bar object.
  Argument:
  x                  : Required. Integer that specifies the x-coordinate of the menu bar object. 
                       Default unit is "px".
  */
  this.setX = function(x) { // Public method
    this.menuBarObj.initialLeft = x;
    this.menuBarObj.style.left = x + "px";
  };
  /*
  Set the y-coordinate of the menu bar object.
  Argument:
  y                  : Required. Integer that specifies the y-coordinate of the menu bar object. 
                       Default unit is "px".
  */
  this.setY = function(y) { // Public method
    this.menuBarObj.initialTop = y;
    this.menuBarObj.style.top = y + "px";
  };
  /*
  Move the menu bar object to the x-coordinate specified by the first argument and the y-coordinate 
  specified by the second argument.
  Arguments:
  x                  : Required. Integer that specifies the x-coordinate of the menu bar object. 
                       Default unit is "px".
  y                  : Required. Integer that specifies the y-coordinate of the menu bar object. 
                       Default unit is "px".
  */
  this.moveTo = function(x, y) { // Public method
    this.menuBarObj.initialLeft = x;
    this.menuBarObj.initialTop = y;
    this.menuBarObj.style.left = x + "px";
    this.menuBarObj.style.top = y + "px";
  };
  /*
  Move the menu bar object towards left by the amount specified by the first argument, and away from 
  top by the amount specified by the second argument. If you want to move the menu bar object towards 
  right, or away from bottom, specify a negative value respectively.
  Arguments:
  x                  : Required. Integer that specifies how much left/right the menu bar object will 
                       move. Default unit is "px".
  y                  : Required. Integer that specifies how much top/bottom the menu bar object will 
                       move. Default unit is "px".
  */
  this.moveBy = function(x, y) { // Public method
    var left = parseInt(this.menuBarObj.style.left);
    var top = parseInt(this.menuBarObj.style.top);
    this.menuBarObj.initialLeft = left + x;
    this.menuBarObj.initialTop = top + y;
    this.menuBarObj.style.left = (left + x) + "px";
    this.menuBarObj.style.top = (top + y) + "px";
  };
  /*
  Set the border width of the menu bar object.
  Argument:
  width              : Required. Integer that specifies the border width of the menu bar object. 
                       Default unit is "px".
  */
  this.setBorderWidth = function(width) { // Public method
    this.menuBarObj.style.borderWidth = width + "px";
  };
  menuBarElm = null;
  dragElm = null;
};

if (typeof(menuBarClassName) == "undefined") {
  var menuBarClassName = "jsdomenubardiv"; // Public field
}

if (typeof(menuBarItemClassName) == "undefined") {
  var menuBarItemClassName = "jsdomenubaritem"; // Public field
}

if (typeof(menuBarItemClassNameOver) == "undefined") {
  var menuBarItemClassNameOver = "jsdomenubaritemover"; // Public field
}

if (typeof(menuBarItemClassNameClick) == "undefined") {
  var menuBarItemClassNameClick = "jsdomenubaritemclick"; // Public field
}

if (typeof(menuBarDragClassName) == "undefined") {
  var menuBarDragClassName = "jsdomenubardragdiv"; // Public field
}

if (typeof(menuBarMode) == "undefined") {
  var menuBarMode = "absolute"; // Public field
}

if (typeof(menuBarActivateMode) == "undefined") {
  var menuBarActivateMode = "click"; // Public field
}

if (typeof(menuBarBorderWidth) == "undefined") {
  var menuBarBorderWidth = 2; // Public field
}

var pt = "padding-top"; // Private field
var pb = "padding-bottom"; // Private field
var menuBarCount = 0; // Private field
var menuBarItemCount = 0; // Private field
var draggingObj = null; // Private field
var staticMenuBarId = new Array(); // Private field

