//Effect types
var MOVE_X_EFFECT = 0;
var MOVE_Y_EFFECT = 1;
var MOVE_Z_EFFECT = 2;
var FADE_EFFECT = 3;
/*
Class: AnimEffect 
Animated effects in 1 dimension
type  - One of the effect types contstants
owner - reference to an AnimtedElement object
tgt - target value for effect
vel - speed of effect
easingFunc - optional pointer to a an easing function
*/
var AnimEffect = function(type, owner, tgt, vel, easingFunc) {
	switch (type){
		case MOVE_X_EFFECT:
			this.initial = owner.x;
			this.update = this.updateMoveX;
			break;
		case MOVE_Y_EFFECT:
			this.initial = owner.y;
			this.update = this.updateMoveY;
			break;
		case MOVE_Z_EFFECT:
			this.initial = owner.z;
			this.update = this.updateMoveZ;
			break;	
		case FADE_EFFECT:
			this.initial = owner.alpha;
			this.update = this.updateFade;
			break;
		default:
			this.update = null;
	}
	this.owner = owner;
	this.current = this.initial;
	this.target = tgt;
	this.velocity = vel;
	this.easingFunc = easingFunc;
	this.isPaused = false;
}

AnimEffect.prototype.updateMoveX = function(){
	this.owner.setX(this.step());
	return (this.inProgress());
}

AnimEffect.prototype.updateMoveY = function(){
	this.owner.setY(this.step());
	return (this.inProgress());
}

AnimEffect.prototype.updateMoveZ = function(){
	this.owner.setZ(this.step());
	return (this.inProgress());
}

AnimEffect.prototype.updateFade = function(){
	this.owner.setAlpha(this.step());
	return (this.inProgress());
}

AnimEffect.prototype.end = function(truncate){
	if(truncate){
		this.target = this.current;
	}
	else{
		this.current = this.target;
		this.update();	
	}
}

AnimEffect.prototype.pause = function(){
	this.isPaused = true;
}

AnimEffect.prototype.resume = function(){
	this.isPaused = false;
}

AnimEffect.prototype.inProgress = function(){
	return (this.current != this.target && this.isPaused == false);	
}

AnimEffect.prototype.step = function(){
	if(this.inProgress()){
		this.current += this.velocity;
		if(this.initial > this.target && this.current < this.target){
			this.current = this.target;	
		}
		else if(this.initial < this.target && this.current > this.target){
			this.current = this.target;	
		}
	}
	return this.current;	
}