         activePopovers.splice(index, 1) if this is popover
 
       @el.detach()
+      @trigger.attr 'aria-expanded', false
       clearInterval @positionInterval
       $(window).unbind 'click', @outsideClickHandler
-
-      @trigger.focus() if @trigger && @trigger.is(':visible')
 
     ignoreOutsideClickSelector: '.ui-dialog'
 

      activePopovers.push(this)
      id = "popover-#{idCounter++}"
      @trigger.attr
        "aria-haspopup" : true
        "aria-owns" : id

      @el
        .attr({
          'id' : id
          'aria-hidden' : false
          'aria-expanded' : true
        })
        .appendTo(document.body)
        .show()
      @el.find(':tabbable').not('.popover_close').first().focus(1)
      @position()

      # handle sticking the carat right above where you clicked on the button, bounded by the dialog
      @el.find(".ui-menu-carat").remove()

      @trigger = $(clickEvent.currentTarget)
      @el = $(@content)
              .addClass('carat-bottom')
              .data('popover', this)
              .keydown (event) =>
                # if the user hits the escape key, reset the focus to what it was.
                if event.keyCode is $.ui.keyCode.ESCAPE
                  @hide()
                  @previousTarget.focus() if @previousTarget and @previousTarget.is(':visible')
                # If the user tabs or shift-tabs away, close.
                return unless event.keyCode is $.ui.keyCode.TAB
                tabbables = $ ":tabbable", @el
                index = $.inArray event.target, tabbables
                return if index == -1

                if event.shiftKey
                  @hide() if index == 0
                else
                  @hide() if index == tabbables.length-1

      @el.delegate '.popover_close', 'click', (event) =>
        event.preventDefault()
        @hide()
        # set focus back to the previously focused item.
        @previousTarget.focus() if @previousTarget and @previousTarget.is(':visible')

      @show(clickEvent)

