 rgb_to_hex = (r, g, b) -> "#" + component_to_hex(r) + component_to_hex(g) + component_to_hex(b)
 
 _loading_threejs_callbacks = []
+
+VERSION = '59'
+#VERSION = '68'
+$.ajaxSetup(cache: true) # when using getScript, cache result.
+
 load_threejs = (cb) ->
     _loading_threejs_callbacks.push(cb)
     #console.log("load_threejs")

        #console.log("load_threejs: already loading...")
        return

    load = (script, cb) -> $.getScript(script).done(()=>cb()).fail(()=>cb("error loading"))

    async.series([
        (cb) -> load("/static/threejs/r59/three.min.js",cb)
        (cb) -> load("/static/threejs/r59/TrackballControls.js",cb)
        (cb) -> load("/static/threejs/Detector.js",cb)
        (cb) ->
            f = () ->
                if THREE?


    init: () =>
        @scene = new THREE.Scene()
        # IMPORTANT: There is a major bug in three.js -- if you make the width below more than .5 of the window
        # width, then after 8 3d renders, things get foobared in WebGL mode.  This happens even with the simplest
        # demo using the basic cube example from their site with R68.
        if opts.width
            @opts.width = Math.min(opts.width, $(window).width()*.5)
        else
            @opts.width  = $(window).width()*.5

        @opts.height = if opts.height? then opts.height else $(window).height()*.6

        if not @opts.renderer?
