// (C) Justin Burt - All Rights Reserved //
//     Version 2.2 - 18th March 2010     //

//***// JumpTask
//***//
//***// Set the coordinates and finish immediately
//***//
function JumpTask( sx,sy ) {
	JumpTask.prototype.getType = function getType() { return "JumpTask"; }
	this.sx = sx;
	this.sy = sy;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	JumpTask.prototype.getX = function getX() {
		return this.sx;
	}
	JumpTask.prototype.getY = function getY() {
		return this.sy;
	}
	JumpTask.prototype.advance = function advance() {
		this.finished = true;
	}
	JumpTask.prototype.start = function start() {
		this.started = true;
	}
	JumpTask.prototype.finish = function finish() {
		this.finished = true;
	}
	JumpTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	JumpTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// MoveTask
//***//
//***// Basic movement on the X and Y axis
//***//
function MoveTask( sx,sy,tx,ty ) {
	MoveTask.prototype.getType = function getType() { return "MoveTask"; }
	this.sx = sx;
	this.sy = sy;
	this.tx = tx;
	this.ty = ty;
	//this.slide =	[0,1,2,3,4,5,6,7,8,10,12,14,16,18,20,23,26,29,32,36,40,44,48,52,56,60,64,68,71,74,77,80,82,84,86,88,90,91,92,93,94,95,96,97,98,99,100];
	this.slide =	[0,1,3,5,7,10,14,18,23,29,36,44,52,60,68,74,80,84,88,91,93,95,97,99,100];
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	MoveTask.prototype.getX = function getX() {
		var dx = this.tx-this.sx;
		return Math.floor( this.sx + ((this.slide[this.step] * dx)/100) );
	}
	MoveTask.prototype.getY = function getY() {
		var dy = this.ty-this.sy;
		return Math.floor( this.sy + ((this.slide[this.step] * dy)/100) );
	}
	MoveTask.prototype.advance = function advance() {
		if (this.started) {
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	MoveTask.prototype.start = function start() {
		this.started = true;
	}
	MoveTask.prototype.finish = function finish() {
		this.finished = true;
	}
	MoveTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	MoveTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// LiftTask
//***//
//***// Movement on the Z axis
//***//
function LiftTask( sz,tz ) {
	LiftTask.prototype.getType = function getType() { return "LiftTask"; }
	this.sz = sz;
	this.tz = tz;
	//this.slide =	[0,1,2,3,4,5,6,7,8,10,12,14,16,18,20,23,26,29,32,36,40,44,48,52,56,60,64,68,71,74,77,80,82,84,86,88,90,91,92,93,94,95,96,97,98,99,100];
	this.slide =	[0,1,3,5,7,10,14,18,23,29,36,44,52,60,68,74,80,84,88,91,93,95,97,99,100];
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	LiftTask.prototype.getZ = function getZ() {
		var dz = this.tz-this.sz;
		return Math.floor( this.sz + ((this.slide[this.step] * dz)/100) );
	}
	LiftTask.prototype.advance = function advance() {
		if (this.started) {
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	LiftTask.prototype.start = function start() {
		this.started = true;
	}
	LiftTask.prototype.finish = function finish() {
		this.finished = true;
	}
	LiftTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	LiftTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// ElevatedMoveTask
//***//
//***// Movement on the X and Y axis while the image rises and falls in an arc during the movement
//***//
function ElevatedMoveTask( sx,sy,sz,tx,ty ) {
	ElevatedMoveTask.prototype.getType = function getType() { return "ElevatedMoveTask"; }
	this.sx = sx;
	this.sy = sy;
	this.sz = sz;
	this.tx = tx;
	this.ty = ty;
	this.tz = sz - 75;
	//this.slide =	[ 0, 1, 2, 3, 4, 5, 6, 7, 8,10,12,14,16,18,20,23,26,29,32,36,40,44,48,52,56,60,64,68,71,74,77,80,82,84,86,88,90,91,92,93,94,95,96,97,98,99,100];
	this.slide =	[0,1,3,5,7,10,14,18,23,29,36,44,52,60,68,74,80,84,88,91,93,95,97,99,100];
	//this.bounce = 	[ 0, 9,16,22,27,31,34,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,50,50,50,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,34,31,27,22,16, 9,  0];
	this.bounce = 	[ 0,16,27,34,37,39,41,43,45,47,49,50,50,49,47,45,43,41,39,37,34,27,16,0];
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	ElevatedMoveTask.prototype.getZ = function getZ() {
		var dz = this.tz-this.sz;
		return Math.floor( this.sz + ((this.bounce[this.step] *2* dz)/100) );
	}
	ElevatedMoveTask.prototype.getX = function getX() {
		var dx = this.tx-this.sx;
		return Math.floor( this.sx + ((this.slide[this.step] * dx)/100) );
	}
	ElevatedMoveTask.prototype.getY = function getY() {
		var dy = this.ty-this.sy;
		return Math.floor( this.sy + ((this.slide[this.step] * dy)/100) );
	}
	ElevatedMoveTask.prototype.advance = function advance() {
		if (this.started) {
			this.zstep+=this.zdir;
			if (this.zstep>=this.slide.length) { this.zstep=this.slide.length-1; this.zdir=-2; }
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	ElevatedMoveTask.prototype.start = function start() {
		this.started = true;
	}
	ElevatedMoveTask.prototype.finish = function finish() {
		this.finished = true;
	}
	ElevatedMoveTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	ElevatedMoveTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}//***// YSpinTask
//***//
//***// Rotation around the Y axis
//***//
function YSpinTask( sr,tr,speed ) {
	YSpinTask.prototype.getType = function getType() { return "YSpinTask"; }
	this.sr = sr
	this.tr = tr;
	if (speed==0) {
		this.slide = 	[0,1,2,4,7,10,15,20,25,75,80,85,90,93,96,98,99,100];
	} else {
		this.slide =	[0,1,2,3,4,5,6,7,8,10,12,14,16,18,20,23,26,29,32,36,40,44,48,52,56,60,64,68,71,74,77,80,82,84,86,88,90,91,92,93,94,95,96,97,98,99,100];
	}
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	YSpinTask.prototype.getRot = function getRot() {
		var dr = this.tr-this.sr;
		return this.sr + ((this.slide[this.step] * dr)/100);
	}
	YSpinTask.prototype.advance = function advance() {
		if (this.started) {
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	YSpinTask.prototype.start = function start() {
		this.started = true;
	}
	YSpinTask.prototype.finish = function finish() {
		this.finished = true;
	}
	YSpinTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	YSpinTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// XSpinTask
//***//
//***// Rotation around the X axis
//***//
function XSpinTask( sr,tr,speed ) {
	XSpinTask.prototype.getType = function getType() { return "XSpinTask"; }
	this.sr = sr
	this.tr = tr;
	if (speed==0) {
		this.slide = 	[0,1,2,4,7,10,15,20,25,75,80,85,90,93,96,98,99,100];
	} else {
		this.slide =	[0,1,2,3,4,5,6,7,8,10,12,14,16,18,20,23,26,29,32,36,40,44,48,52,56,60,64,68,71,74,77,80,82,84,86,88,90,91,92,93,94,95,96,97,98,99,100];
	}
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	XSpinTask.prototype.getRot = function getRot() {
		var dr = this.tr-this.sr;
		return this.sr + ((this.slide[this.step] * dr)/100);
	}
	XSpinTask.prototype.advance = function advance() {
		if (this.started) {
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	XSpinTask.prototype.start = function start() {
		this.started = true;
	}
	XSpinTask.prototype.finish = function finish() {
		this.finished = true;
	}
	XSpinTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	XSpinTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// XSpinReplaceTask
//***//
//***// Rotation around the X axis which can change the image at the 50% rotation mark
//***//
function XSpinReplaceTask( newsrc,speed) {
	XSpinReplaceTask.prototype.getType = function getType() { return "XSpinReplaceTask"; }
	this.newimg = new Image();
	this.newimg.src = newsrc;
	this.sr = 0
	this.tr = Math.PI*2;
	if (speed==0) {
		this.slide = [0,1,2,4,7,10,15,20,25,75,80,85,90,93,96,98,99,100];
	} else {
		this.slide = [0,1,2,3,4,5,6,7,8,9,10,11,13,15,17,19,21,23,25,75,77,79,81,83,85,87,89,90,91,92,93,94,95,96,97,98,99,100];
	}
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	this.half = Math.floor(this.slide.length/2);
	
	var that =		this;
	
	XSpinReplaceTask.prototype.getImage = function getImage() {
		if (this.step!=this.half+2) {
			return null;
		} else {
			return this.newimg;
		}
	}
	XSpinReplaceTask.prototype.getRot = function getRot() {
		var dr = this.tr-this.sr;
		return this.sr + ((this.slide[this.step] * dr)/100);
	}
	XSpinReplaceTask.prototype.advance = function advance() {
		if (this.started) {
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	XSpinReplaceTask.prototype.start = function start() {
		this.started = true;
	}
	XSpinReplaceTask.prototype.finish = function finish() {
		this.finished = true;
	}
	XSpinReplaceTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	XSpinReplaceTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// YSpinReplaceTask
//***//
//***// Rotation around the Y ayis which can change the image at the 50% rotation mark
//***//
function YSpinReplaceTask( newsrc,speed ) {
	YSpinReplaceTask.prototype.getType = function getType() { return "YSpinReplaceTask"; }
	this.newimg = new Image();
	this.newimg.src = newsrc;
	this.sr = 0
	this.tr = Math.PI*2;
	if (speed==0) {
		this.slide = [0,1,2,4,7,10,15,20,25,75,80,85,90,93,96,98,99,100];
	} else {
		this.slide = [0,1,2,3,4,5,6,7,8,9,10,11,13,15,17,19,21,23,25,75,77,79,81,83,85,87,89,90,91,92,93,94,95,96,97,98,99,100];
	}
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	this.half = Math.floor(this.slide.length/2);
	
	var that =		this;
	
	YSpinReplaceTask.prototype.getImage = function getImage() {
		if (this.step!=this.half+2) {
			return null;
		} else {
			return this.newimg;
		}
	}
	YSpinReplaceTask.prototype.getRot = function getRot() {
		var dr = this.tr-this.sr;
		return this.sr + ((this.slide[this.step] * dr)/100);
	}
	YSpinReplaceTask.prototype.advance = function advance() {
		if (this.started) {
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	YSpinReplaceTask.prototype.start = function start() {
		this.started = true;
	}
	YSpinReplaceTask.prototype.finish = function finish() {
		this.finished = true;
	}
	YSpinReplaceTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	YSpinReplaceTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// DelayTask
//***//
//***// Delays the processing of further queued tasks until all previous tasks have finished
//***//
function DelayTask() {
	DelayTask.prototype.getType = function getType() { return "DelayTask"; }
	this.started =	false;
	this.finished = false;
	
	DelayTask.prototype.advance = function advance() {
	}
	DelayTask.prototype.start = function start() {
		this.started = true;
	}
	DelayTask.prototype.finish = function finish() {
		this.finished = true;
	}
	DelayTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	DelayTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// WaitTask
//***//
//***// Delays the processing of further queued tasks until a specified number of frames have passed
//***//
function WaitTask( step ) {
	WaitTask.prototype.getType = function getType() { return "WaitTask"; }
	this.step = 1+step;
	this.started =	false;
	this.finished = false;
	
	WaitTask.prototype.advance = function advance() {
		if (--this.step<=0) { this.finished = true; }
	}
	WaitTask.prototype.start = function start() {
		this.started = true;
	}
	WaitTask.prototype.finish = function finish() {
		this.finished = true;
	}
	WaitTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	WaitTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// XOrientationTask
//***//
//***// Allows changing of the orientation in the middle of a queued sequence
//***//
function XOrientationTask() {
	XOrientationTask.prototype.getType = function getType() { return "XOrientationTask"; }
	this.started =	false;

	XOrientationTask.prototype.advance = function advance() {
	}
	XOrientationTask.prototype.start = function start() {
		this.started = true;
	}
	XOrientationTask.prototype.finish = function finish() {
		this.finished = true;
	}
	XOrientationTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	XOrientationTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// YOrientationTask
//***//
//***// Allows changing of the orientation in the middle of a queued sequence
//***//
function YOrientationTask() {
	YOrientationTask.prototype.getType = function getType() { return "YOrientationTask"; }
	this.started =	false;

	YOrientationTask.prototype.advance = function advance() {
	}
	YOrientationTask.prototype.start = function start() {
		this.started = true;
	}
	YOrientationTask.prototype.finish = function finish() {
		this.finished = true;
	}
	YOrientationTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	YOrientationTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// BounceTask
//***//
//***// Smooth bounce on the Z axis, either up or down
//***//
function BounceTask( sz,range ) {
	BounceTask.prototype.getType = function getType() { return "BounceTask"; }
	this.sz = sz;
	this.tz = sz+range;
	this.slide =	[0,28,48,61,67,67,61,48,28,0,-13,-10,6,-3,-1,0];
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	BounceTask.prototype.getZ = function getZ() {
		var dz = this.tz-this.sz;
		return Math.floor( this.sz + ((this.slide[this.step] *2* dz)/100) );
	}
	BounceTask.prototype.advance = function advance() {
		if (this.started) {
			this.zstep+=this.zdir;
			if (this.zstep>=this.slide.length) { this.zstep=this.slide.length-1; this.zdir=-2; }
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	BounceTask.prototype.start = function start() {
		this.started = true;
	}
	BounceTask.prototype.finish = function finish() {
		this.finished = true;
	}
	BounceTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	BounceTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// DropTask  
//***//
//***// Gravity drop on Z axis with terminal bounce. SZ is the final Z coordinate, range is from how far to fall to it
//***//
function DropTask( sz,range ) {
	DropTask.prototype.getType = function getType() { return "DropTask"; }
	this.sz = sz;
	this.tz = sz+range;
	this.slide =	[100,98,97,95,91,85,78,69,55,39,20,0,-10,-13,-15,-13,-10,6,8,6,-3,-4,-2,-1,0];
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	DropTask.prototype.getZ = function getZ() {
		var dz = this.tz-this.sz;
		return Math.floor( this.sz + ((this.slide[this.step] * dz)/100) );
	}
	DropTask.prototype.advance = function advance() {
		if (this.started) {
			this.zstep+=this.zdir;
			if (this.zstep>=this.slide.length) { this.zstep=this.slide.length-1; this.zdir=-2; }
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	DropTask.prototype.start = function start() {
		this.started = true;
	}
	DropTask.prototype.finish = function finish() {
		this.finished = true;
	}
	DropTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	DropTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// FadeTask
//***//
//***// Opacity transition from SO to TO (scale 0-1)
//***//
function FadeTask( so,to ) {
	FadeTask.prototype.getType = function getType() { return "FadeTask"; }
	this.so = so;
	this.to = to;
	this.slide =	[0,2,4,6,8,12,16,20,26,32,40,48,56,64,71,77,82,86,90,92,94,96,98,100];
	this.step = 	0;
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	FadeTask.prototype.getO = function getO() {
		var dx = this.to-this.so;
		return ( this.so + ((this.slide[this.step] * dx)/100) );
	}
	FadeTask.prototype.advance = function advance() {
		if (this.started) {
			if (++this.step == this.slide.length) {
				this.step-=1;
				this.finished = true;
			}
		}
	}
	FadeTask.prototype.start = function start() {
		this.started = true;
	}
	FadeTask.prototype.finish = function finish() {
		this.finished = true;
	}
	FadeTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	FadeTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}
//***// HideTask
//***//
//***// Instantly set the opacity to zero and then finish
//***//
function HideTask() {
	HideTask.prototype.getType = function getType() { return "HideTask"; }
	this.started =	false;
	this.finished = false;
	
	var that =		this;
	
	HideTask.prototype.advance = function advance() {
		this.finished = true;
	}
	HideTask.prototype.start = function start() {
		this.started = true;
	}
	HideTask.prototype.finish = function finish() {
		this.finished = true;
	}
	HideTask.prototype.isStarted = function isStarted() {
		return this.started;
	}
	HideTask.prototype.isFinished = function isFinished() {
		return this.finished;
	}
}

