function ParallaxRegister::registerObject(%this, %object, %scrollFactor)
{
   if(getWordCount(%this.objects) == 0)
      %this.objects = %object;
   else
      %this.objects = %this.objects SPC %object;
      
   if(getWordCount(%this.scrollFactors) == 0)
      %this.scrollFactors = %scrollFactor;
   else
      %this.scrollFactors = %this.scrollFactors SPC %scrollFactor;
}

function ParallaxRegister::unregisterObject(%this, %object)
{
   %wordIndex = 0;
   %found = false;
   while(!%found && %wordIndex < %numberOfObjects)
   {
      %currentObject = getWord(%this.objects, %i);
      if(%object == %currentObject)
      {
         %found = true;
         removeWord(%this.objects, %i);
         removeWord(%this.scrollFactors, %i);
      }
   }
}

function ParallaxRegister::unregisterAllObjects(%this)
{
   %this.objects = "";
}

function ParallaxRegister::startScrolling(%this)
{
   %numberOfObjects = getWordCount(%this.objects);
   for(%i = 0; %i < %numberOfObjects; %i++)
   {
      %currentObject = getWord(%this.objects, %i);
      %currentScrollFactor = getWord(%this.scrollFactors, %i);
      %currentObject.setLinearVelocityX(sceneWindow2D.getScrollSpeed() * (1 - %currentScrollFactor) * -1);
   }
}

function ParallaxRegister::stopScrolling(%this)
{
   %numberOfObjects = getWordCount(%this.objects);
   for(%i = 0; %i < %numberOfObjects; %i++)
   {
      %currentObject = getWord(%this.objects, %i);
      %currentObject.setLinearVelocityX(0);
   }
}

// create parallax register object
new ScriptObject(parallaxReg)
{
   class = "ParallaxRegister";
   objects = "";
   scrollFactors = "";
};