/**
 * DropDownMenu for global navi
 * Powered by hisato http://chibinowa.net/
 * http://sjam.chibinowa.net/eid/162
 */
var DropDownMenu = {
  /* 開くまでの待ち時間 */
  open_sleep: 100,
  /* 閉じるまでの待ち時間 */
  close_sleep: 500,

  timer: null,
  active_oid: null,

  // 開くメイン
  open: function(target_id)
  {
    // 開いているメニューを閉じる
    if (this.timer) {
      if (this.active_oid == target_id)
        clearTimeout(this.timer);
      else
        this._close();
    }
    this.active_oid = target_id;
    this.timer = setTimeout("DropDownMenu._open();", this.open_sleep);
    //Event.observe(document.documentElement, "click", DropDownMenu._close, true);
    $(document.documentElement).bind("click", DropDownMenu._close);
  },

  // 閉じるメイン
  close: function()
  {
    if (this.timer)
      clearTimeout(this.timer);
    this.timer = setTimeout("DropDownMenu._close();", this.close_sleep);
  },

  _open: function()
  {
    var obj = document.getElementById(this.active_oid);
    obj.style.visibility = "visible";
  },

  _close: function()
  {
    document.getElementById(DropDownMenu.active_oid).style.visibility = "hidden";
    //Event.stopObserving(document.documentElement, "click", DropDownMenu._close, true);
    $(document.documentElement).unbind("click");
    clearTimeout(DropDownMenu.timer);
    delete DropDownMenu.timer;
  }

};

