/* path module javascript code
 * based on	dynlite dhtml dom api
 * @author: Peter Assenov- AIP Solutions Ltd.' 2001-2007
 * @version: 2.2.0.4/2007-05-14
 */
/* module initialization */
ver_path='2.2'; /* Module version */
if(window.ver&&ver_path!=ver) error('Incorect dynlite version: '+ver+', should be: '+ver_path,'path.js','Path init','Include');
/* class definition*/
function path(id,duration,frate)
{	/* external configuration */
	this.id=id||'path_';
	this.duration=duration||1; 	/* the transition period in seconds */
	this.frate=frate||20;		/* animation framerate i.e iterations per second */
	/* internal variables */
	this.i=0;
	this.dir=0;
	this.steps=0;
	this.time=0;
	this.interval=0;
window[this.id]=this;
}
_path=path.prototype;
_path.evoke=function(evt,e){ if(this[evt]) this[evt](e);}
_path.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.frate);
/* 	Points coordinates follows a 1D Bezier curve with 3 control points
 *  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;
}
_path.step=function()
{	this.i+=this.dir;
	this.evoke('onstep');
	if(!this.i||this.i==this.steps)
	{	clearInterval(this.interval);
		this.evoke('onend',this.dir);
	}
}
_path.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);
}
_path.stop=function()
{	clearInterval(this.interval);
	this.evoke('onstop');
}
/* path module end */