/* pathe module javascript code
 * based on	dynlite dhtml dom api
 * @author: Peter Assenov- AIP Solutions Ltd.' 2001-2007
 * @version: 2.2.0.3/2007-06-20
 * @requires: dynlite.1.0.js
 * @requires: app.1.0.js
 */
function path(id,duration,frate)
{	/* external configuration */
	this.id=id||'path_';	/* need to be overwritten by the derivate class */
	this.duration=duration||4; 	/* the transition period in seconds */
	this.frate=frate||5;		/* animation framerate i.e iterations per second */
	/* internal variables */
	this.i=0;
	this.dir=0;
	this.interval=0;
	this.steps=0;
	this.time=0;
}
pap=path.prototype;
pap.evoke=function(evt,e){ if(this[evt]) this[evt](e);}
pap.calc=function(p0,p1,p2)
{	var p0=p0||0;
	var p1=p1||100;
	var p2=p2||p1;
	var points=[];
	this.steps=parseInt(this.duration*this.frate);
	this.time=parseInt(1000/this.steps*this.duration);
/* 	Points coordinates follows a 1D Bezier curve with 3 control point
 *  Original C source of bezier curve is taken from: http://local.wasp.uwa.edu.au/~pbourke/surfaces_curves/bezier/index2.html
 *	f(x)=p0*(1-x)^2+2*P1*(1-x)*x+P2*x^2
 */
	for(var i=this.steps;i>=0;i--)
	{	var x=i/this.steps;
		var x2=x*x;
		var mx=1-x;
		var mx2=mx*mx;
		points[i]=Math.round(p0*mx2+2*p1*mx*x+p2*x2);
	}
return points;
}
pap.step=function()
{	this.i+=this.dir;
	this.i=(this.i<0)? 0 : (this.i>=this.steps)? this.steps : this.i;
	this.evoke('onstep');
	if(!this.i||this.i==this.steps)
	{	clearInterval(this.interval);
		this.evoke('onend',this.dir);
	}
}
pap.go=function(dir)
{	clearInterval(this.interval);
	this.dir=(dir)? dir:(this.dir==1)? -1:1;
	this.evoke('onstart');
	this.interval=setInterval(this.id+".step()",this.time);
}
pap.stop=function()
{	clearInterval(this.interval);
	this.evoke('onstop');
}
pap.reset=function(p0,p1,p2)
{	clearInterval(this.interval);
	this.i=0;
	this.dir=0;
}

/* path module end */