   back: (e) ->
     e.preventDefault()
 
-    # Prevent multiple clicks
-    @undelegateEvents()
+    @undelegateEvents() # Prevent multiple clicks
     
     @trigger 'sfx:play', 'button'
     @trigger 'scene:change', 'difficulty'
 
-  # Parse through a level object and display on a table
-  showPreview: (level) ->
+  showLevelInfo: ->
+    # TODO move this elsewhere
     pad = (number, length) ->
       string = String(number)
       string = '0' + string while string.length < length

        'touchend .previous': 'previous'
        'touchend .next': 'next'
        'touchend .play': 'play'
    else
      events =
        'click .back': 'back' 
        'click .previous': 'previous'
        'click .next': 'next'
        'click .play': 'play'

  current: 0
  page: 0
  difficulty: 'easy'
  stats: {}


    @$('.attempts').html "Attempts: #{attempts}"
    @$('.best-time').html "Best Time: #{time}"

    levelData = levels[@difficulty][@current]

    # If level is completed, show preview, title, etc.
    if time != '--:--'
      @$('.level-number').html "#{@difficulty.charAt(0).toUpperCase() + @difficulty.slice(1)} ##{@current + 1}: #{levelData.title}"
    else
      @$('.level-number').html "#{@difficulty.charAt(0).toUpperCase() + @difficulty.slice(1)} ##{@current + 1}: ????"
      @$('.preview .complete').hide()
      @$('.preview .incomplete').show()

  drawPreviews: ->
    i = 0
    while (i < @perPage)
      canvas = @$('.preview canvas').eq(i)
      pixelSize = Math.floor(canvas.width() / 10)
      context = canvas[0].getContext('2d')
      context.clearRect(0, 0, canvas.width(), canvas.height())

      levelData = levels[@difficulty][@page * @perPage + i]

      if levelData is undefined
        canvas.hide()
      else
        canvas.show()
        for clue, index in levelData.clues
            if clue is 1
              x = index % 10
              y = Math.floor(index / 10)
              context.fillRect(x * pixelSize, y * pixelSize, pixelSize, pixelSize)
      i += 1

  select: (event) ->
    @current = @page * @perPage + $(event.target).index()
    @highlightPreview()

  highlightPreview: ->
    index = @current - @page * @perPage
    preview = @$('canvas').eq(index)
    preview.siblings().removeClass 'selected'
    preview.addClass 'selected'
    @showLevelInfo()

  resize: (width, height, orientation) ->
    preview = @$('.preview')

    # TODO: Get rid of this hardcoded nonsense
    if orientation is 'landscape'
      width = width * 0.4
      preview.width(Math.round(width / 10) * 10)
