//=======================================================\\
//                    Anderemedia.nl                     \\
//                   Copyright (c) 2003                  \\ 
//=======================================================\\

	make.prototype.moves = new Array();    
	make.prototype.cancelMoves = false;     
	make.prototype.moving = false;
	
	make.prototype.timeSlide = function(x,y,duration,acc,func,cancel,timeout) {
		if(!cancel) var cancel = false;
		if(!func) var func = "null";
		if(!timeout) var timeout = 5;
		if(!acc) var acc = 0;
		
		var startTime = new Date().valueOf();
		var endTime = startTime + duration;
		
		if(!this.moving) {	
			this.moving = true;
			this.timeSlideAux(this.x,this.y,x,y,acc,startTime,endTime,func,cancel,timeout);
		} else {
			if(cancel) {		
				this.cancelMoves = true;
				this.moves = new Array();
			}
			
			var strExec = this.obj + ".timeSlide(" + x + "," + y + "," + duration + "," + acc + ",'" + func + "'," + cancel + "," + timeout + ")";
			this.moves.push(strExec);			
		}
	}
	
	make.prototype.timeSlideAux = function(startX,startY,endX,endY,acc,startTime,endTime,func,cancel,timeout) {
		var curTime = new Date().valueOf();
		if(this.cancelMoves) {
			this.moving = false;
			this.cancelMoves = false;
			if(this.moves[0]) eval(this.moves.shift());
			
		} else if(curTime >= endTime) {
			this.moveTo(endX,endY);
			this.moving = false;
			if(func) eval(func);
			if(this.moves[0]) eval(this.moves.shift());
			
		} else {
			var percent = (curTime - startTime) / (endTime - startTime); 
			var startPos = new coord(1,1);
			var endPos = new coord(0,0);	
					
			if(acc!=0) var c1 = new coord(0.5+(acc/2),0.5-(acc/2));
			else c1 = null;
			var pos = getBezier(percent,startPos,endPos,c1);
			var stage = pos.y;
	
			this.moveTo(((endX-startX)*stage)+startX,((endY-startY)*stage)+startY);
			

			var strExec = this.obj + ".timeSlideAux(" + startX + "," + startY + "," + endX + "," + endY + "," + acc + "," + startTime + "," + endTime + ",'" + func + "'," + cancel + "," + timeout + ")";
			setTimeout(strExec,timeout);
			
		}
	}
	

	make.prototype.bezierSlide = function(x,y,c1x,c1y,c2x,c2y,duration,acc,func,cancel,timeout) {
		if(!cancel) var cancel = false;
		if(!func) var func = "null";
		if(!timeout) var timeout = 5;
		if(!acc) var acc = 0;
		
		var startTime = new Date().valueOf();
		var endTime = startTime + duration;
		
		if(!this.moving) {	
			this.moving = true;
			this.bezierSlideAux(this.x,this.y,x,y,c1x,c1y,c2x,c2y,acc,startTime,endTime,func,cancel,timeout);
		} else {
			if(cancel) {		
				this.cancelMoves = true;
				this.moves = new Array();
			}
			var strExec = this.obj + ".bezierSlide(" + x + "," + y + "," + c1x + "," + c1y + "," + c2x + "," + c2y + "," + duration + "," + acc + ",'" + func + "'," + cancel + "," + timeout + ")";
			this.moves.push(strExec);			
		}
	}
	
	make.prototype.bezierSlideAux = function(startX,startY,endX,endY,c1x,c1y,c2x,c2y,acc,startTime,endTime,func,cancel,timeout) {
		var curTime = new Date().valueOf();
		if(this.cancelMoves) {
			this.moving = false;
			this.cancelMoves = false;
			if(this.moves[0]) eval(this.moves.shift());
			
		} else if(curTime >= endTime) {
			this.moveTo(endX,endY);
			this.moving = false;
			if(func) eval(func);
			if(this.moves[0]) eval(this.moves.shift());
			
		} else {
			var percent = (curTime - startTime) / (endTime - startTime);
			var startPos = new coord(0,0);
			var endPos = new coord(1,1);	
					
			if(acc!=0) var c1 = new coord(0.5-(acc/2),0.5+(acc/2));
			else c1 = null;
			var pos = getBezier(percent,startPos,endPos,c1);
			var stage = pos.y;
	
			var startPos = new coord(startX,startY);
			var endPos = new coord(endX,endY);
			var c1 = new coord(c1x,c1y);
			var c2 = new coord(c2x,c2y);
			var pos = getBezier(stage,startPos,endPos,c1,c2);
			this.moveTo(pos.x,pos.y);

			var strExec = this.obj + ".bezierSlideAux(" + startX + "," + startY + "," + endX + "," + endY + "," + c1x + "," + c1y + "," + c2x + "," + c2y + "," + acc + "," + startTime + "," + endTime + ",'" + func + "'," + cancel + "," + timeout + ")";
			setTimeout(strExec,timeout);
			
		}
	}


	
	make.prototype.doCancelMoves = function(keepCurrent) {
		if(keepCurrent) this.cancelMoves = true;
		this.moves = new Array();
	}


	B1 = function(t) { return (t*t*t); }
	B2 = function(t) { return (3*t*t*(1-t)); }
	B3 = function(t) { return (3*t*(1-t)*(1-t)); }
	B4 = function(t) { return ((1-t)*(1-t)*(1-t)); }
	
	coord = function (x,y) { if(!x) var x=0; if(!y) var y=0; return {x: x, y: y}; }
	

	function getBezier(percent,startPos,endPos,control1,control2) {
		
		if(!control2 && !control1) var control2 = new coord(startPos.x + 3*(endPos.x-startPos.x)/4, startPos.y + 3*(endPos.y-startPos.y)/4);
		if(!control2) var control2 = control1;
		if(!control1) var control1 = new coord(startPos.x + (endPos.x-startPos.x)/4, startPos.y + (endPos.y-startPos.y)/4);
				
		var pos = new coord();
		pos.x = startPos.x * B1(percent) + control1.x * B2(percent) + control2.x * B3(percent) + endPos.x * B4(percent);
		pos.y = startPos.y * B1(percent) + control1.y * B2(percent) + control2.y * B3(percent) + endPos.y * B4(percent);
		
		return pos;
	}
