function sceneWindow2D::onMouseMove(%this, %modifier, %worldPos, %mouseClicks)
{
   // level scrolling
   %mousePosX = getWord(%worldPos, 0);
   %currentCameraPositionX = getWord(%this.getCurrentCameraPosition(), 0);
   %mousePosXToCamera = %mousePosX - %currentCameraPositionX;
   
   if(!sceneWindow2D.getIsCameraMoving())
   {
      if(%mousePosXToCamera < -58.5)
         %this.scrollLeft();
      else if(%mousePosXToCamera > 58.5)
         %this.scrollRight();
   }
   else if(%mousePosXToCamera > -58.5 && %mousePosXToCamera < 58.5)
      %this.stopScrolling();
}

function sceneWindow2D::scrollLeft(%this)
{
   %currentCameraPosition = sceneWindow2D.getCurrentCameraPosition();
   %currentCameraPositionX = getWord(%currentCameraPosition, 0);
   %currentCameraPositionY = getWord(%currentCameraPosition, 1);
   
   %distanceToDestination = (%currentCameraPositionX - -64);
   %timeToDestination = mAbs(%distanceToDestination / 64);
   %scrollSpeed = %distanceToDestination / %timeToDestination;
   
   %this.setTargetCameraPosition(-64, %currentCameraPositionY);
   %this.scrollSpeed = %scrollSpeed;
   %this.startCameraMove(%timeToDestination);
   parallaxReg.startScrolling();
   %this.schedule(1, "updateScrolling");
}

function sceneWindow2D::scrollRight(%this)
{
   %currentCameraPosition = sceneWindow2D.getCurrentCameraPosition();
   %currentCameraPositionX = getWord(%currentCameraPosition, 0);
   %currentCameraPositionY = getWord(%currentCameraPosition, 1);
   
   %distanceToDestination = (%currentCameraPositionX - 64);
   %timeToDestination = mAbs(%distanceToDestination / 64);
   %scrollSpeed = %distanceToDestination / %timeToDestination;
   
   %this.setTargetCameraPosition(64, %currentCameraPositionY);
   %this.scrollSpeed = %scrollSpeed;
   %this.startCameraMove(%timeToDestination);
   parallaxReg.startScrolling();
   %this.schedule(1, "updateScrolling");
}

function sceneWindow2D::stopScrolling(%this)
{
   parallaxReg.stopScrolling();
   %this.stopCameraMove();
   %this.scrollSpeed = 0;
}

function sceneWindow2D::updateScrolling(%this)
{
   if(!%this.getIsCameraMoving())
      parallaxReg.stopScrolling();
   else
      %this.schedule(1, "updateScrolling"); 
}

function sceneWindow2D::getScrollSpeed(%this)
{
   return %this.scrollSpeed;
}