                 toggleQueueElement.click()
 
 
+class Viewport
+        constructor: (@document) ->
+                _.extend @, Backbone.Events
+                @decoratorHeight = $("#content", @document).height()
+                @playlistHeight = $(@document).height() - @decoratorHeight
+                $(".remove-after-height-calculation", @document).remove()
+                @lastSizeUpdate = 0
+
+        _updateHeight: =>
+                @playlistHeight = $(@document).height() - @decoratorHeight
+                @trigger "resize"
+
+        _bind: =>
+                $(@document).resize =>
+                        @lastSizeUpdate++
+                        currentUpdate = @lastSizeUpdate
+                        updateCallback = =>
+                                if @lastSizeUpdate != currentUpdate
+                                        return
+                                @_updateHeight()
+                        setTimeout updateCallback, RESIZE_UPDATE_DELAY
+
 $(document).ready ->
         audio = new Audio();
         playbackType = null

        for song in queue.fullQueue()
                queueData.push songToQueueRow song

        # Magical numbers based on Stetson-Harrison method.
        playlistHeight = queueElement.data 'targetHeight'

        table = queueElement.dataTable
                sScrollY: "#{playlistHeight}px"
                sScrollX: "100%"
                sScrollXInner: "100%"
                bScrollCollapse: false


        router = new PlayerRouter()

        viewport = new Viewport document

        queueTable = $("#queue")
        playlist = $("#playlist")
        QueueView $("#toggle-queue"), queueTable, songQueue, playerInstance, playlist, viewport

        search = new Search localStorage

