         window.clearTimeout(timeout) while (timeout = timeouts.pop())
 
         colours = []
-        index = 1
         win = $(document)
         [width, height] = [$(document).width(), $(document).height()]
 

        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)
