   setResultsFor: (query, results) ->
     @store[this.getKey(query)] = results
 
-class OUT.QuickJump
-  DELAY_BEFORE_SERVER_CALL: 300
-  FETCHING_RESULTS: "fetching"
-  DICTIONARY_KEY_LENGTH: 1
+class OUT.QuickJump.Controls
   KEY_UP: 38
   KEY_DOWN: 40
   KEY_ENTER: 13
   KEY_ESC: 27
-  MAX_RESULTS: 10
-
-  constructor: (@result_callback, @data_url = "/quick_jump_targets.json", selector = "#quick-jump-template") ->
+  
+  constructor: (@parent, @selector, @result_callback) ->
     @active_result = null
-    @dictionary = new OUT.QuickJumpDictionary(@DICTIONARY_KEY_LENGTH)
-
-    @selector = this.cloneModal(selector)
-    this.setDefaultResults()
-    self = this
-
-    $(@selector).bind "hidden", ->
-      $(self.selector).remove()
-
-    $(@selector).bind "shown", ->
-      $(self.selector+" input").select()
-
-    $(@selector).modal().modal("show")
-
+    self = this
     $(@selector+" input[type=text]").bind "keydown", (event) ->
       val = self.keydown(event)
       if val == false


$(window).load ->
  OUT.registerKeyboardShortcut "t", ->
    new OUT.QuickJump (selected) ->
      window.location.href = selected.url

        event.stopPropagation()
      val

  keydown: (event) ->
    if event.keyCode == @KEY_ENTER
      @parent.activateResult()
      false
    else if event.keyCode == @KEY_UP
      @parent.moveSelection(-1)
      false
    else if event.keyCode == @KEY_DOWN
      @parent.moveSelection(+1)
      false

  keyup: (event) ->
    query = event.target.value
    if query != @old_query
      if query == ""
        @parent.setDefaultResults()
      else if query.length >= @parent.DICTIONARY_KEY_LENGTH
        @parent.setOrRequestResults(query)
    @old_query = query



class OUT.QuickJump.Base
  DELAY_BEFORE_SERVER_CALL: 300
  FETCHING_RESULTS: "fetching"
  DICTIONARY_KEY_LENGTH: 1
  MAX_RESULTS: 10

  constructor: (@result_callback, @data_url = "/quick_jump_targets.json", selector = "#quick-jump-template") ->
    @dictionary = new OUT.QuickJump.Dictionary(@DICTIONARY_KEY_LENGTH)
    @selector = this.cloneModal(selector)
    @controls = new OUT.QuickJump.Controls(this, @selector, @result_callback)
    this.setDefaultResults()

    self = this
    $(@selector).bind "hidden", ->
      $(self.selector).remove()

    $(@selector).bind "shown", ->
      $(self.selector+" input").select()

    $(@selector).modal().modal("show")

  activateResult: (anchor) ->
    anchor or= this.getActiveResult()
    if anchor?
