 [rectWidth, rectHeight] = [60, 60]
+
+UPDATE_INTERVAL = 1000
 
 # Initialised by reset().
 checkDoneInterval = null
 colours = null
 context = null
 height = null
-index = null
 start = null
 width = null
+
+sort_context = null
 
 # We set this after document is ready.
 canvas = null

        context.fillRect(val2.x, val2.y, rectWidth, rectHeight)

isort = ->
        for j in [index...0]
                swapRects(j - 1, j) if colours[j - 1].val > colours[j].val

        index++
        defer(isort) if index < colours.length

# Selection sort
# @author Bernhard Häussner (https://github.com/bxt)

        start = Date.now()

        initColours()
        sort_context = null
        defer(sort)

        checkDoneInterval = window.setInterval(checkDone, 10)
