       @canvas.id = "can"
       @ctx = @canvas.getContext "2d"
       @canvas.setAttribute "id","#{@globalID}_canvas"
+      @canvas.style.cursor  = "move"
 
       @canvasWrapper = document.createElement "div"
       @canvasWrapper.appendChild @canvas

      @tilesX = Math.ceil(@canvas.width / @tileSize)
      @tilesY = Math.ceil(@canvas.height / @tileSize)

      console.log "#tiles x:" + @tilesX + ",y:" + @tilesY

      @canvas.addEventListener "mousemove", (e) =>
        @_onmousemove e

      @canvas.addEventListener "dblclick", (e) =>
        @_onDblClick e

      @canvas.addEventListener "mousedown", (e) =>
        return
        @_onmousedown e
      @canvas.addEventListener "mouseup", (e) =>
        @_onmouseup e

      @canvas.addEventListener "mouseout", (e) =>
        @_onmouseout e

      @map = []

      @viewportX = 120
      @viewportY = 100
      @dblClickVx = 1
      @dblClickVy = 1

      #@animate()
      @timestamp = 0

    _onmousemove: (e) ->
      if @dragStartX? and @draglock?
        distX= e.pageX - @dragStartX
        distY = e.pageY - @dragStartY

        @viewportX = @dragViewStartX - distX
        @viewportY = @dragViewStartY - distY

        @checkPos()

        #@draw()
        console.log "#viewx:" + @viewportX + ",y:" + @viewportY
        console.log "#tiles x:" + distX + ",y:" + distY
        @pauseEvent e

    _onmouseup: (e) ->
      @draglock = undefined

    _onmouseout: (e) ->
      @draglock = undefined

    _onmousedown: (e) ->
      @pauseEvent e
      @dragStartX = e.pageX
      @dragStartY = e.pageY
      @dragViewStartX = @viewportX
      @dragViewStartY = @viewportY
      @draglock = true

    _onDblClick: (e) ->

      #if not @rect? or @rect?.left is 0
      #  @rect = @canvas.getBoundingClientRect()

      # center the view on double click
      mouseX = e.offsetX
      mouseY = e.offsetY

          #console.log "tile i:" + tileX + ",j:" + tileY
          @ctx.putImageData tile,tileX,tileY
          #@ctx.drawImage tile,tileX,tileY

      # control overlays

      # zoom control
      @ctx.fillStyle = "red"
      @ctx.fillRect @canvas.width - 40, @canvas.height - 35,15,15
      callback = -> alert "hi"
      @events.zoomIn = [@canvas.width - 40, @canvas.height - 35,15,15,callback]

      @ctx.fillStyle = "blue"
      @ctx.fillRect @canvas.width - 40, @canvas.height - 20,15,15
      @events.zoomOut = [@canvas.width - 40, @canvas.height - 20,15,15,callback]

      return @canvasWrapper

