 Wrapper =
   interface: null
 
-  # handleKeyEvent: (event) ->
-  #   switch event.type
-  #     when "keydown"
-  #       @interface?.onKeyDown event
-  #     when "keyup"
-  #       @interface?.onKeyUp event
-
   init: ->
-    # handleKeyEvent = (event) => @handleKeyEvent event
-    # for name in [ "keydown", "keyup" ]
-    #   Common.installListener window, name, handleKeyEvent
-
+    Common.installListener window, "keydown", (event) => @interface?.onKeydown event
+    Common.installListener window, "keyup", (event) => @interface?.onKeyup event
+    Common.installListener window, "scroll", (event) => @interface?.onScroll event
+
+    Scroller.init()
     @launch()
 
     chrome.runtime.onMessage.addListener (request, sender, sendResponse) =>

      "visible"

  selectElement: (element, shouldScroll = true) ->
    Common.log "selectElement #{element?} #{shouldScroll} #{@isEnabled}" if @debug.select
    Common.log "              #{element == @element} (expect false for a new element)" if @debug.select
    if element and @isEnabled
      @clearSelection()
      @element = document.activeElement = element


      false

  launch: ->
    element = @interface?.element
    @interface?.deactivate()
    @interface = null

    chrome.runtime.sendMessage { name: "config", url: document.location.toString() }, (config) =>
      Common.log "config:", config?.name ? "disabled"
      @interface = new Interface(config, element) if config

Common.documentReady -> Wrapper.init()

