   (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")
 

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

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

bindHotkeyWithoutMeta = (hotkey, fn) -> bindHotkey hotkey, (event) -> fn(event) if not event.metaKey

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


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

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

bindKey "/", (event) -> focusElement(event, '#q')

bindKey "p", -> ifTargets -> setTarget previousTarget()
bindKey "k", -> ifTargets -> setTarget previousTarget()
bindKey "n", -> ifTargets -> setTarget nextTarget()
bindKey "j", -> ifTargets -> setTarget nextTarget()

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

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

bindKey "c", (event) ->
  onlyExchanges -> visitLink('.functions .create')
  onlyPosts     -> focusElement(event, '#compose-body')

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