function AdjustWaterLevel(%Water, %LevelChange, %Time, %SlowingFactor)
{
   // If the Object you specified to increase in size is not water, just
   // note that in the console and log and quit
   if (%Water.getType() != 16)
   {
      logEcho("Attempting to raise/lower water level on non-water object.");
      Echo("Attempting to raise/lower water level on non-water object.");
      return;
   }

   // If asked to increase at a rate that would look tacky, then note
   // that in the console and log and quit
   %IntervalSize = %LevelChange / %Time;
   if (%IntervalSize > 0.133)
   {
      logEcho("Attempting to raise/lower water level too quickly, can not be more than 8 meters per minute.");
      Echo("Attempting to raise/lower water level too quickly, can not be more than 8 meters per minute.");
      return;
   }

   // Determine if the interval of 0.1 or 0.05 per time is better fitting and then adjust
   // timing delays to compensate
   if (%IntervalSize < 0.02)
   {
      %TimeInterval = 0.05 / %IntervalSize;
      %IntervalSize = 0.05;
      
   } else {
      %TimeInterval = 0.1 / %IntervalSize;
      %IntervalSize = 0.1;         
   }

   // Make sure a slowing factor is defined, even if it is 1 (which is disabled)
   if (%SlowingFactor $= "" || %SlowingFactor <= 0)
      %SlowingFactor = 1;

   // Work backwards and invert the scaling factor half way so that when it rolls forward it
   // evens out by starting faster and then slowing down.
   %Changes = %LevelChange / %IntervalSize;

   if (%SlowingFactor != 1)
   {
      %HalfChanges = %Changes / 2;

      %i = 0;
      while (%i < %HalfChanges)
      {
         %IntervalSize /= %SlowingFactor;

         %i++;
      }
   }

   %Water.Locked = true;

   // Loop through and schedule the resizing of the water now.   
   %i = 1;
   while (%i <= %Changes)
   {
      %IntervalSize *= %SlowingFactor;

      Schedule(%i * %TimeInterval * 1000, 0, SizeWater, %Water, %IntervalSize);
   
      %i++;   
   }
}

function SizeWater(%Water, %Change)
{
   %ScaleXY = getWords(%Water.Scale, 0, 1);
   %ScaleZ = getWord(%Water.Scale, 2) + %Change;

   %Water.Scale = %ScaleXY @ " " @ %ScaleZ;

   // Just needed to cause a refresh
   %Water.setTransform(%Water.getTransform());
}