code: function tabBrowser_closeTab(aEvent) {
      var event = aEvent || { };
      var type = (event.type == undefined) ? "menu" : event.type;
  
      // Disable tab closing animation for default behavior
      prefs.preferences.setPref(PREF_TABS_ANIMATE, false);
  
      // Add event listener to wait until the tab has been closed
      var self = { closed: false };
      function checkTabClosed() { self.closed = true; }
      this._controller.window.addEventListener("TabClose", checkTabClosed, false);
  
      switch (type) {
        case "closeButton":
          var button = this.getElement({type: "tabs_tabCloseButton",
                                       subtype: "tab", value: this.getTab()});
          this._controller.click(button);
          break;
        case "menu":
          var menuitem = new elementslib.Elem(this._controller.menus['file-menu'].menu_close);
          this._controller.click(menuitem);
          break;
        case "middleClick":
          var tab = this.getTab(event.index);
          this._controller.middleClick(tab);
          break;
        case "shortcut":
          var cmdKey = utils.getEntity(this.getDtds(), "closeCmd.key");
          this._controller.keypress(null, cmdKey, {accelKey: true});
          break;
        default:
          throw new Error(arguments.callee.name + ": Unknown event type - " + type);
      }
  
      try {
        this._controller.waitForEval("subject.tab.closed == true", TIMEOUT, 100,
                                     {tab: self});
      } finally {
        this._controller.window.removeEventListener("TabClose", checkTabClosed, false);
        prefs.preferences.clearUserPref(PREF_TABS_ANIMATE);
      }
    }
docs: Close an open tab
  
  @param {object} aEvent
  The event specifies how to close a tab
  Elements: type - Type of event (closeButton, menu, middleClick, shortcut)
  [optional - default: menu]