//__________________________________________________________________________________________animation
var animation = {
  targets:new Array(),
  define:function(id,path,type) {
    this.object=document.getElementById(id)
    this.element=(this.object) ? this.object.style : null
    this.type=(type) ? type : "MOVE"
    this.active=0
    this.timer=null
    this.path=(path) ? path : new Array()
    this.num=null
    switch (this.type) {
      case "MOVE":this.statement="this.path=this.path.reverse()"; break
      case "SLIDE":this.statement="this.path=this.path.reverse()"; break
      case "SCROLL":this.statement="this.path=this.path.reverse()"; break
      default:this.statement=""
    }
    this.name=id
    eval("animation.targets."+this.name + "=this")

    this.reassign=function(id,type) {
      if (this.active) this.stop();
      this.object=document.getElementById(id)
      this.element = (this.object) ? this.object.style : null
      this.type = (type) ? type : "MOVE"
    }
    this.animate=function(interval) {
      if (this.active) return
      if (((this.type=="MOVE") || (this.type=="SCROLL")) && (this.path.length==0)) return
      if ((this.type.substr(0,3)=="OPA") && (this.path.length!=0)) return
      this.show()
      this.num=0
      this.active=1
      this.timer=setInterval("animation.targets['"+this.name+"'].step()", interval)
    }
    this.step = function () {
      switch (this.type) {
        case "MOVE": 
          this.moveTo(this.path[this.num].x, this.path[this.num].y)
          if (this.num >= this.path.length - 1) this.stop()
          else this.num++
          break
        case "SLIDE": 
          this.slide(this.path[this.num].y)
          if (this.num >= this.path.length - 1) this.stop()
          else this.num++
          break
        case "OPA40FADE": this.setOpacity(-6,40,100); break
        case "OPA40FOCUS": this.setOpacity(6,40,100); break
        case "OPA70FADE": this.setOpacity(-6,70,100); break
        case "OPA70FOCUS": this.setOpacity(6,70,100); break
        case "SCROLL": 
          window.scrollTo(this.path[this.num].x, this.path[this.num].y)
          if (this.num >= this.path.length - 1) this.stop()
          else this.num++
          break
        others: this.stop()
      }   
    }
    this.stop = function () {
      clearInterval(this.timer)
      this.active = 0
      if (this.statement) eval(this.statement)
    }
    this.show=function() { if (this.element) this.element.visibility = (IE()) ? "visible" : "show"; }
    this.hide=function() { if (this.element) this.element.visibility = (IE()) ? "hidden" : "hide"; }
    this.left=function() { if (this.element) return parseInt(this.element.left); }
    this.top=function() { if (this.element) return parseInt(this.element.top); }
    this.moveTo=function(x,y) { 
      if ((x) || (y)) {
        this.element.left=x; 
        this.element.top=y; 
      } else if (!this.path.length==0) {
        this.element.left=this.path[0].x; 
        this.element.top=this.path[0].y; 
      }
    }
    this.slide=function(y) { 
	  if (!this.element) alert('DIV element unavailable: '+this.name)
      if (y) this.element.top=y
      else if (!this.path.length==0) this.element.top=this.path[0].y
    }
    this.setOpacity = function(step,low,high) {
      if (!this.object) return 
      var opacity=(IE()) ? this.object.filters.alpha.opacity : (this.object.style.MozOpacity*100)
      if (((step<0) && (opacity==low)) || ((step>0) && (opacity==high))) this.stop()
      else opacity+=step
      if (opacity<low) opacity = low
      if (opacity>high) opacity = high
      if (IE()) this.object.filters.alpha.opacity=opacity 
      else this.object.style.MozOpacity=opacity/100
    }
  },  
  slideToPath:function(fromx, fromy, tx, ty, steps, xfactor) { // xfactor should be between 0.8 and 4
    var fx = fromx;
    var fy = fromy;
    var dx = tx - fx;
    var dy = ty - fy;
    var sx = dx / steps;
    var sy = dy / steps;
    var ar = new Array();
    var stepInc = 1;
    ar[ar.length]=new pos(fromx,fromy);
    for (var i=0;i<steps;i++) {
      fx += sx;
      fy += sy;
      if (xfactor) {
        if (Math.round(stepInc)==(i+1)) {
          stepInc*=xfactor*2;
          ar[ar.length]=new pos(fx, fy);
        }
      } else ar[ar.length]=new pos(fx, fy);
    }
    ar[ar.length]=new pos(tx,ty);
    return ar;
  },
  circlePath:function(x,y,r,startAngle,totalDegrees,stepCount,flatFactor,scewFactor,spiralFactor) {
    var xPos;
	var yPos;
    var degree;
    var ar=new Array();
// Set some defaults (in case they are not supplied)
    if (!stepCount) stepCount=30;
    if (!totalDegrees) totalDegrees=360;
    if (!startAngle) startAngle=0;
    var stepSize=totalDegrees/stepCount;

    for (var runDown=0;runDown<=totalDegrees;runDown+=stepSize) {
      degree = startAngle + runDown % 360;
      if (spiralFactor) r *= spiralFactor;
// Flatten the circle
      if (flatFactor) xPos = x - (r/flatFactor) * Math.cos(degree * Math.PI / 180);
      else xPos = x - r * Math.cos(degree * Math.PI / 180);
      yPos = y + r * Math.sin(degree * Math.PI / 180);
// apply: x=y/scewFactor
      if (scewFactor) xPos -= (yPos-y) / scewFactor;
      ar[ar.length]=new pos(xPos, yPos);
    }
    return ar;
  },
  flatCirclePath:function(fromx, fromy, tox, toy, steps) {
    var hdr=new Array();
    var ftr=new Array();
    var middlex=(fromx+tox)/2;
    var middley=(fromy+toy)/2;
  
    hdr=new animation.slideToPath(fromx,fromy,middlex,middley,steps,0.8);
    ftr=new animation.slideToPath(tox,toy,middlex,middley,steps,0.8);
    hdr.pop();hdr.pop();ftr.pop(); 
    return hdr.concat(ftr.reverse());
  }
}  

