/*
Glide types:
linear,

Direction: x,y
L or R
T or B

End coordinate to end at
Completion:
together,
seperate
*/


function glider(div,type,completion,x,y,startX,startY,endX,endY)
{
  this.div = div;
  this.slideType = type;
  this.completion = completion;
  this.duration = 25;
  this.X = x;
  this.Y = y;
  this.endX = endX;
  this.endY = endY;
  this.currentStepX = startX;
  this.currentStepY = startY;
  //calculate step
  this.travelX = Math.abs(startX - this.endX);
  this.travelY = Math.abs(startY - this.endY);
  this.intervalID;
  if(this.travelX > this.travelY)
  {
    this.stepX = Math.round((this.travelX/this.travelY) * 5);
    this.stepY = 5;
  }
  else
  {
    this.stepY = Math.round((this.travelY/this.travelX)*5);
    this.stepX = 5;
  }
  this.move = function()
  {
    var moved = false;
    this.currentStepX += this.stepX;
    this.currentStepY += this.stepY;
    if(this.X == "L" && this.endX > this.currentStepX)
    {
      this.div.style.left = this.currentStepX + "px";
      moved = true;
    }
    if(this.X == "R" && this.endX > this.currentStepX)
    {
      this.div.style.right = this.currentStepX + "px";
      moved = true;
    }
    if(this.Y == "T" && this.endY > this.currentStepY)
    {
      this.div.style.top = this.currentStepY + "px";
      moved = true;
    }
    if(this.Y == "B" && this.endY > this.currentStepY)
    {
      this.div.style.bottom = this.currentStepY + "px";
      moved = true;
    }
    if(!moved)
      window.clearInterval(this.intervalID);
  };
  this.intervalID = window.setInterval("document.getElementById(\'"+this.div.id+"\').glider.move()",this.duration);
};