// animatedObject()
// object constructor for the animated objects.

function animatedObject(elementName,loop,speed,steps,endRoutines,route){
  this.elementName = elementName;
  this.loop = loop;
  this.speed = speed;
  this.steps = steps;
  this.frameIndex = 0;
  this.endRoutines = endRoutines;
  this.route = route.split(',');
  this.animate = animateObject;
  this.move = moveObject;
  this.show = showObject;
  this.hide = hideObject;

  animatedObjects[elementName] = this;
}

// stopTimeline()
// stops a timeline, pass it the timeline's number.

function stopTimeline(timelineNumber){
   animationTime[timelineNumber] = animationTimeline[timelineNumber].length;
}

// startTimeline()
// starts a timeline, just pass it the timeline's number.

function startTimeline(timelineNumber) {
  animationTime[timelineNumber] = 0;
  timelineController(timelineNumber);
}

// timelineController()
// controls timeline, recurisively runs itself every 100 milliseconds.

function timelineController(timelineNumber) {
    if (animationTime[timelineNumber] <= animationTimeline[timelineNumber].length - 1) {
      animationTime[timelineNumber]++;
        if (animationTimeline[timelineNumber][animationTime[timelineNumber]] != null){
          eval(animationTimeline[timelineNumber][animationTime[timelineNumber]]);
        }
        setTimeout('timelineController(' + timelineNumber + ')', 100);
    }
}

// showObject()
// makes an HTML element visible.

function showObject(){
  eval(layerObj + '["' + this.elementName + '"]' + styleObj + '.visibility = "visible"');
}
        
// showObject()
// makes an HTML element hidden.
function hideObject(){
  eval(layerObj + '["' + this.elementName + '"]' + styleObj + '.visibility = "hidden"');
}
  
// moveObject()
// moves an HTML element to a given position.
// Pass it the and x and y coordinates.

function moveObject(left, top){
  eval(layerObj + '["' + this.elementName + '"]' + styleObj + '.top = top');
  eval(layerObj + '["' + this.elementName + '"]' + styleObj + '.left = left');
}

// doAnimation()
// interprets the animated object's properties then animates the animated object.
// pass it the number of the animated object.

function animateObject(){
    if (this.route.length > 4 && this.frameIndex < this.route.length)  {
      this.move(this.route[this.frameIndex], this.route[this.frameIndex + 1]);
      this.frameIndex += 2;
      setTimeout('animatedObjects["' + this.elementName + '"].animate()', this.speed);
    }
    else if (this.route.length == 4 && this.frameIndex <= this.steps) {
      this.move(parseInt(this.route[0]) + (this.frameIndex * ((parseInt(this.route[2]) - parseInt(this.route[0])) / this.steps)), parseInt(this.route[1]) + (this.frameIndex * ((parseInt(this.route[3]) - parseInt(this.route[1])) / this.steps)));
      this.frameIndex++;
      setTimeout('animatedObjects["' + this.elementName + '"].animate()', this.speed);         
    }
    else {
      eval(this.endRoutines + "");
      this.frameIndex = 0;
        if (this.loop == "yes"){
          this.animate();
        }
    }
}