var Animators = new Array ();

	
Animate = function ()
{
	this.index = Animators.append( this );
	this.obj = null;
	this.distX = 0;
	this.distY = 0;
	this.destX = 0;
	this.destY = 0;
	this.moveX = 0;
	this.moveY = 0;
}

Animate.prototype = {


	strait : function ( obj, destX, destY, firstTime )
	{
		if ( firstTime )
		{
			if ( obj.style.position != 'absolute' )
				obj.style.position = 'absolute';

			if ( obj.style.left == '' || obj.style.top == '')
			{
				var pos = getPosition( obj );
				obj.style.left = pos[0] + 'px';
				obj.style.top = pos[1] + 'px';
			}

			this.obj = obj;
			this.destX = destX;
			this.destY = destY;

			var diffX = destX - parseInt( obj.style.left );
			var diffY = destY - parseInt( obj.style.top );

			this.distX = diffX / ( Math.abs( diffX ) + Math.abs( diffY ) );
			this.distY = diffY / ( Math.abs( diffX ) + Math.abs( diffY ) );
		}

		obj = this.obj;
		var objX = parseInt( obj.style.left );
		var objY = parseInt( obj.style.top );

		if ( ( this.distX > 0 && objX < this.destX ) || ( this.distX < 0 && objX > this.destX ) )
		{
			this.moveX += this.distX;
			if ( this.moveX >= 1 || this.moveX <= -1)
			{
				obj.style.left = objX + this.moveX + 'px';
				if ( this.moveX > 0 )
					this.moveX -= Math.floor( this.moveX );
				else
					this.moveX -= Math.ceil( this.moveX );
			}
		}

		if ( ( this.distY > 0 && objY < this.destY ) || ( this.distY < 0 && objY > this.destY ) )
		{
			this.moveY += this.distY;
			if ( this.moveY >= 1 || this.moveY <= -1)
			{
				obj.style.top =  objY + this.moveY + 'px';
				if (this.moveY > 0)
					this.moveY -= Math.floor( this.moveY );
				else
					this.moveY -= Math.ceil( this.moveY );
			}
		}

		if ( ( this.distX > 0 && objX < this.destX ) || ( this.distX < 0 && objX > this.destX ) 
			|| ( this.distY > 0 && objY < this.destY ) || ( this.distY < 0 && objY > this.destY ) )
			setTimeout ( 'Animators[' + this.index + '].strait()', 1 ); 


	}

}

