 
   #addBaseElements adds the common base elements to the ElementBox
   addBaseElements: ->
-    @addElement((box, x, y) -> new BaseElements.Controller(box, x, y, 0))
-    @addElement((box, x, y) -> new BaseElements.Router(box, x, y, 0))
-    @addElement((box, x, y) -> new BaseElements.Switch(box, x, y, 0))
+    @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

    @height = @ve.height
    @width = @ve.width
    @baseRect = new Shapes.Rectangle(0x262626, 0, 0, 0, @width, @height)
    @ve.scene.add(@baseRect.obj3d)

#VisualEnvironment holds the state associated with the Threejs objects used

    @renderer.setClearColor(@clear, @alpha)
    @container.appendChild(@renderer.domElement)
    @camera.position.z = 100
    @mouseh = new MouseHandler(this)
    @raycaster = new THREE.Raycaster()

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

#Mouse handler encapsulates the logic of dealing with mouse events
class MouseHandler

  constructor: (@ve) ->
    @pos = new THREE.Vector2(0, 0)

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

  #onmousedown handlers
  baseDown: (event) ->
    @updateMouse(event)
    @ve.raycaster.setFromCamera(@pos, @ve.camera)
    ixs = @ve.raycaster.intersectObjects(@ve.scene.children, true)
    if ixs.length > 1 and
      ixs[1].object.userData instanceof ElementBox and
      ixs[0].object.userData.cyjs?
        e = ixs[0].object.userData
        console.log "! ebox select -- " + e.constructor.name
        console.log e
        @ve.container.onmousemove = (eve) => @placingMove(eve)
        @ve.container.onmousedown = (eve) => @placingDown(eve)

  placingDown: (event) ->
    console.log "plop"
    @ve.container.onmousemove = null
    @ve.container.onmousedown = (eve) => @baseDown(eve)

  #onmousemove handlers
  placingMove: (event) ->
    @updateMouse(event)

