/***************************************************************************
	Animate - Animate object.
	
	An object that suports the basic 'move()' method that the Animation 
	object uses. This in turn supports the 'findTarget()' and update()

	
	Version:
		v0.1, Monday, July 08, 2002
	
	Requires:
		UniDom v0.1+
		
	Author:
		Alexander Whillas

	Copyright (C) 2002 Taylor Square Designs
***************************************************************************/
function Animate (p_div_id, p_speed) {
	// Call the parent objects constructor.
	this.parent = UniDom;
	this.parent(p_div_id);
	
	this.target = new Point();
	this.SPEED = p_speed || 0.1;

	return this;	
}
Animate.prototype = new UniDom;

// Moves the object one step towards its new target Point. Should be called 
// by the main animation loop (see the Animation object).
Animate.prototype.move = function () {
	if(this.isActive()) {
		this.findTarget();
		this.update();
	}
}

/**
	Determines the next position the object should be tring to get to and
	updates the this.target Point property. Override this if you want it to
	behave other than linear movement.
*/
Animate.prototype.findTarget = function () {
}

/* 
	Moves the object towards its next position (this.target) in linear 
	fashion. Override this if you want different behaviour.
	
	NB: If STEP equals zero or null then it will move directly to the 
	target point.
*/
Animate.prototype.update = function () {

	// Horzontal and vertical distances to target.
	x_dis = this.target.getX() - this.getX();
	y_dis = this.target.getY() - this.getY();

	// Increment from the current position.
	return this.moveBy( Math.round(x_dis * this.SPEED), Math.round(y_dis * this.SPEED));
}

Animate.prototype.isActive = function () {
	return !this.isEqualTo(this.target);
}