// --------------------------------------------------
//		(c) SingularIT 2001
// --------------------------------------------------
/*
Multi-Object animation lib.
Objects supported:
[ SinLayer, State, IC ]

function SIN_makeAnimatable() {
function SIN_startAni( endx, endy ) {
function SIN_ani() {
*/

var aoa = new Array(); // ANIMATION OBJECT ARRAY
var ANICOUNT = -1;
var ANIMODE = true;
// --------------------------------------------------
function SIN_makeAnimatable() {
// --------------------------------------------------
	this.aoa = aoa.length;
	aoa[aoa.length] = this;

	this.animating = false;
	this.StartX = 0;
	this.StartY = 0;
	this.EndX = 0;
	this.EndY = 0;
	this.EndY = 0;
	this.aniSpeed = 8;
	if(browser.ns6) this.aniSpeed /= 2;
	this.timeOut = null;

	this.aniExe = "";

	this.startAni = SIN_startAni;
	this.ani = SIN_ani;
}
// --------------------------------------------------
function SIN_startAni( endx, endy, aniSpeed) {
// --------------------------------------------------
	// CALCULATE IF ANI IS NECESSARY
	var ONSCREEN = true;
	var t = (browser.ns4)?window.pageYOffset:document.body.scrollTop;
	var l = (browser.ns4)?window.pageXOffset:document.body.scrollLeft;
	var b = browser.height + t;
	var r = browser.width + r;
	if(this.y+this.h<t || this.y>b || this.x+this.w<l || this.x>r) ONSCREEN = false;

	if(t < endy < b) ONSCREEN = true;
	else if(l < endx < r) ONSCREEN = true;

	if(ANIMODE && ONSCREEN) {
		this.animating = true;
		this.StartX = this.x;
		this.StartY = this.y;
		this.EndX = endx;
		this.EndY = endy;
		this.aniSpeed = (aniSpeed!=null) ? aniSpeed : this.aniSpeed;

		if(this.timeOut != null) {
			clearTimeout(this.timeOut);
			ANICOUNT--;
		}
		ANICOUNT++;
		this.ani();
	}
	else {
		this.EndX = endx;
		this.EndY = endy;
		this.MoveTo(endx, endy);
	}
}

// --------------------------------------------------
function SIN_ani() {
// --------------------------------------------------
// calculate next x coordinate
	if (this.EndX > this.StartX) {
		this.x += Math.floor((this.EndX - this.x) / this.aniSpeed) + 1;
		if (this.x > this.EndX) this.x = this.EndX;
	}
	else {
		this.x += Math.floor((this.EndX - this.x) / this.aniSpeed) - 1;
		if (this.x < this.EndX) this.x = this.EndX;
	}
// calculate next y coordinate
	if (this.EndY > this.StartY) {
		this.y += Math.floor((this.EndY - this.y) / this.aniSpeed) + 1;
		if (this.y > this.EndY) this.y = this.EndY;
	}
	else {
		this.y += Math.floor((this.EndY - this.y) / this.aniSpeed) - 1;
		if (this.y < this.EndY) this.y = this.EndY;
	}
	this.MoveTo(this.x,this.y);

	if (this.x != this.EndX || this.y != this.EndY ) {
		this.timeOut = eval("setTimeout('aoa[" + this.aoa + "].ani()',10)");
	}
	else {
		clearTimeout(this.timeOut);
		this.timeOut = null;
		this.animating = false;
		ANICOUNT--;
		if(this.aniExe){
			eval(this.aniExe);
			this.aniExe = "";
		}
	}
}

