         #console.log("load_threejs: already loading...")
         return
 
-    load = (script, cb) -> $.getScript(script).done(()=>cb()).fail(()=>cb("error loading"))
+    load = (script, cb) -> $.getScript(script).done((script, textStatus)=>cb()).fail((jqxhr, settings, exception )=>cb("error loading -- #{exception}"))
 
     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) -> load("/static/threejs/r#{VERSION}/three.min.js",cb)
+        (cb) -> load("/static/threejs/r#{VERSION}/TrackballControls.js",cb)
+        (cb) -> load("/static/threejs/r#{VERSION}/Detector.js",cb)
         (cb) ->
             f = () ->
                 if THREE?

    render_scene: (force=false) =>
        #console.log('render', @opts.element.length)
        @opts.element.show()
        
        if @controls?
            @controls?.update()
        else

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")
