 
 #Global event handlers
 root.vz_mousedown = (event) ->
-  g.ve.handle_mousedown(event)
+  g.ve.mouseh.ondown(event)
 
 #Global state holder
 g = {}

    @renderer.setClearColor(@clear, @alpha)
    @container.appendChild(@renderer.domElement)
    @camera.position.z = 100
    @mouse = new THREE.Vector2(0, 0)
    @raycaster = new THREE.Raycaster()

  render: ->
    @renderer.render(@scene, @camera)

  updateMouse: (event) ->
    @mouse.x =  (event.layerX / @container.offsetWidth ) * 2 - 1
    @mouse.y = -(event.layerY / @container.offsetHeight) * 2 + 1
    console.log(@mouse.x + "," + @mouse.y)

  handle_mousedown: (event) ->
    @updateMouse(event)
    @raycaster.setFromCamera(@mouse, @camera)
    ixs = @raycaster.intersectObjects(@scene.children, true)
    console.log "!" if ixs.length > 0



  #addBaseElements adds the common base elements to the ElementBox
  addBaseElements: ->
    @addElement((box, x, y) -> new BaseElements.Controller(box, x, y, 5))
    @addElement((box, x, y) -> new BaseElements.Router(box, x, y, 5))
    @addElement((box, x, y) -> new BaseElements.Switch(box, x, y, 5))

#The Surface holds visual representations of Systems and Elements
class Surface
