     e.preventDefault()
     Prez.current?.end()
 
+$(document).on "keydown", Prez.handlers.keyDown
+
 $ ->
     $("#in-window-not-implemented-modal").modal show: false

        $(".prez-slide", @document).each (i) -> $(@).attr "data-slide", "#{i + 1}"
        @changeSlideTo 1 unless changeToHashSlide()
        $(@window).on "hashchange", changeToHashSlide

    changeSlideTo: (nextValue) ->
        $next = $ ".prez-slide[data-slide='#{nextValue}']", @document

    nextSlide: -> @changeSlideBy 1
    prevSlide: -> @changeSlideBy -1
    end: -> @window.close()

    KEY_LEFT = 37
    KEY_RIGHT = 39

    @handlers:
        keyDown: (e) ->
            return if $(e.target).is("input, textarea, select, option")

            switch e.which
                when KEY_LEFT
                    e.preventDefault()
                    Prez.current?.prevSlide()
                when KEY_RIGHT
                    e.preventDefault()
                    Prez.current?.nextSlide()

$(document).on "click", "#new-window", (e) ->
    return if Prez.current
