function Mover()
{
  this.collection = [];
  this.count = 0;
}

function _Mover_add(objId, top, left, percent)
{
   this.collection[this.count] = {objId: objId, top: top, left: left, percent: percent};

   ++this.count;
}

Mover.prototype.add = _Mover_add;

function _Mover_go(callbackFunc)
{
  //document.body.style.overflow = 'hidden';
  var i, n = this.count, obj;
  for(i = 0; i < n; ++i)
  {
    obj = $(this.collection[i].objId);
    if(obj)
    {
      this.collection[i].obj = obj;
      this.collection[i].movingObject = new MovingObject(obj);
      obj.style.display = 'block';

      if(this.collection[i].percent)
      {
        this.collection[i].percent = obj.offsetLeft * 100 / document.body.offsetWidth;
      }

      //obj.style.top = document.body.offsetHeight + document.documentElement.scrollTop + obj.offsetHeight + 'px';
      obj.style.top = document.documentElement.scrollHeight - obj.offsetHeight + 'px';

      this.collection[i].movingObject.go(this.collection[i].left || obj.offsetLeft, this.collection[i].top);
    }
  }

  if(n)
  {
    var timer = setInterval(isFinished, 100);
  }

  var self = this;
  function isFinished()
  {
    for(i = 0; i < n; ++i)
    {
      if(!self.collection[i].movingObject.finished)
      {
        return;
      }
    }

    clearInterval(timer);

    for(i = 0; i < n; ++i)
    {
      if(self.collection[i].percent)
      {
        self.collection[i].obj.style.left = self.collection[i].percent + '%';
      }
    }

    if(callbackFunc)
    {
      callbackFunc();
    }

    //document.body.style.overflow = 'auto';
  }
}

Mover.prototype.go = _Mover_go;


