// object constructor
function menuDropObj(menuId, dropId, leftJig, topJig) {

  //define the object's properties
  this.menu = (document.getElementById(menuId) != null) ? document.getElementById(menuId) : null;
  this.menuId = menuId;
  this.drop = (document.getElementById(dropId) != null) ? document.getElementById(dropId) : null;
  this.dropId = dropId;

  this.dropLeft = null;
  this.dropTop = null;
  this.leftJig = leftJig;
  this.topJig = topJig;

  //attach object's methods
  this.Show = menuDropObjShowMenu;
  this.Hide = menuDropObjHideMenu;

//  this.drop.style.visibility = "hidden";
//  this.drop.style.position = "absolute";
}

//this function shows the menu
function menuDropObjShowMenu() {

  if (this.drop == null || this.menu == null) {

    this.menu = document.getElementById(this.menuId);
    this.drop = document.getElementById(this.dropId);
  }

  if (this.dropLeft == null || this.dropTop == null) {

    this.dropLeft = menuDropObjCalcOffset("left", this.menu) + this.leftJig;
    this.dropTop = menuDropObjCalcOffset("top", this.menu) + this.topJig;

    this.drop.style.left = this.dropLeft;
    this.drop.style.top = this.dropTop;
  }

  this.drop.style.visibility = "visible";
}

//this function hides the menu
function menuDropObjHideMenu() {

  if (this.drop == null || this.menu == null) {

    this.menu = document.getElementById(this.menuId);
    this.drop = document.getElementById(this.dropId);
  }

  this.drop.style.visibility = "hidden";
}



//helper method to calculate the top and left
//offset of an object
function menuDropObjCalcOffset(type, menu) {

  var offset = 0;
  var curObj = menu;

  while (curObj != null) {

    if (type.toLowerCase() == "left")
      offset = offset + curObj.offsetLeft;
    else
      offset = offset + curObj.offsetTop;

    curObj = curObj.offsetParent;      
  }

  return offset;
}