   (elemTop < top) or (elemBottom > bottom)
 
 exchangeId = (target) -> $(target).closest('tr').data('exchange-id')
+
+focusElement = (event, selector) ->
+  $(selector).focus()
+  event.preventDefault()
 
 isDiscussion = (target) -> $(target).closest('tr').hasClass("discussion")
 

bindKeySequence /gi$/, -> visitPath('/invites')
bindKeySequence /gu$/, -> visitPath('/users/online')

bindHotkeyWithoutMeta "shift+p", (event) -> visitLink('.prev_page_link')
bindHotkeyWithoutMeta "shift+k", (event) -> visitLink('.prev_page_link')
bindHotkeyWithoutMeta "shift+n", (event) -> visitLink('.next_page_link')
bindHotkeyWithoutMeta "u",       (event) -> visitLink('#back_link')
bindHotkeyWithoutMeta "shift+j", (event) -> visitLink('.next_page_link')

bindHotkey "/", (event) ->
  $('#q').focus()
  event.preventDefault()

bindHotkeyWithoutMeta "p", (event) -> setTarget previousTarget()
bindHotkeyWithoutMeta "k", (event) -> setTarget previousTarget()
bindHotkeyWithoutMeta "n", (event) -> setTarget nextTarget()
bindHotkeyWithoutMeta "j", (event) -> setTarget nextTarget()

bindHotkeyWithoutMeta "r", (event) -> onlyPosts -> Sugar.loadNewPosts()
bindHotkeyWithoutMeta "q", (event) -> onlyPosts -> withTarget (target) -> Sugar.quotePost(target)

bindHotkeyWithoutMeta "o",            (event) -> onlyExchanges -> withTarget (target) -> openTarget(target)
bindHotkeyWithoutMeta "shift+o",      (event) -> onlyExchanges -> withTarget (target) -> openTargetNewTab(target)
bindHotkeyWithoutMeta "Return",       (event) -> onlyExchanges -> withTarget (target) -> openTarget(target)
bindHotkeyWithoutMeta "shift+Return", (event) -> onlyExchanges -> withTarget (target) -> openTargetNewTab(target)
bindHotkeyWithoutMeta "y",            (event) -> onlyExchanges -> withTarget (target) -> markAsRead(target)
bindHotkeyWithoutMeta "m",            (event) -> onlyExchanges -> withTarget (target) -> markAsRead(target)

bindHotkeyWithoutMeta "c", (event) ->
  onlyExchanges -> visitLink('.functions .create')
  onlyPosts ->
    $("#compose-body").focus()
    event.preventDefault()

$(Sugar).bind "ready", -> resetTarget()

  114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 144, 145, 191
]

bindRawKey = (hotkey, fn) -> $(document).bind "keydown", hotkey, fn

bindKey = (hotkey, fn) -> bindRawKey hotkey, (event) -> fn(event) if not event.metaKey

bindKeySequence = (expression, fn) -> keySequences.push([expression, fn])

