 			
 			{ lastPosition, changedCallback } = @
 
+			# regular mouse management
 			unless @locked 
 				if @buttonDown
 					distX = -(evt.pageX - lastPosition.x)
 					distY =   evt.pageY - lastPosition.y
-					changedCallback.x distX/SLOWDOWN_FACTOR if distX isnt 0
-					changedCallback.y distY/SLOWDOWN_FACTOR if distY isnt 0
+					changedCallback.x distX / SLOWDOWN_FACTOR if distX isnt 0
+					changedCallback.y distY / SLOWDOWN_FACTOR if distY isnt 0
 
 				@lastPosition =
 					x : evt.pageX
 					y : evt.pageY
+
+			# fullscreen API 
+			# Mouse lock returns MovementX/Y in addition to the regular properties
+			# (these become static)		
 			else
-				if @buttonDown	
-					distX = -evt.webkitMovementX
-					distY = evt.webkitMovementY
-					changedCallback.x distX/SLOWDOWN_FACTOR if distX isnt 0
-					changedCallback.y distY/SLOWDOWN_FACTOR if distY isnt 0
+				distX = -evt.originalEvent.webkitMovementX
+				distY = evt.originalEvent.webkitMovementY
+				changedCallback.x distX / SLOWDOWN_FACTOR if distX isnt 0
+				changedCallback.y distY / SLOWDOWN_FACTOR if distY isnt 0
 
 		mouseDown : =>
 			$(@target).css("cursor", "none")


		buttonDown : false
		
		# used for mopuse locking in fullscreen mode
		locked : false

		lastPosition : 
			x : null
			y : null

		target : null

		changedCallback :  
			x : $.noop()
			y : $.noop() 

		###
		#@param {Object} objectToTrack :
		#	HTML object where the mouse has to attach the events
		###
		constructor : (objectToTrack) ->
		
			@target = objectToTrack
			@attachEventHandler "mousemove", @mouseMoved
			@attachEventHandler "mouseup", @mouseUp
			@attachEventHandler "mousedown", @mouseDown

			# fullscreen pointer lock 
			@attachEventHandler "webkitfullscreenchange", @lockMouse
			@attachEventHandler "webkitPointerlocklost", @unlockMouse
			@attachEventHandler "mozfullscreenchange", @lockMouse
		
		###
		#Binds a function as callback when X-Position was changed
		#@param {Function} callback :

			@buttonDown = false 
			$(@target).css("cursor", "auto")

		toogleMouseLock : =>
			unless @locked
				if (navigator.pointer)
					navigator.pointer.lock @target, ( -> console.log "Mouse Lock successful" ), ( -> console.log "Error: Mouse Lock" )
					@locked = true
			else
				@locked = false
				navigator.pointer.unlock()
