
	//Mark Wise : 03-08-2006 : 09-10-2007 : 5 : Interval
	
	//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
																			
	Interval = function(){
		
		this.offset = 0;      //object start position 
		this.qm = 0;          //displacement magnitude, the distance to move
		this.d = 0;           //duration, the number of frames to move the object in
		this.fps = 30;        //frames per second
		this.motionType; 	  //the motion algorithym to use
		this.q = 0;			  //displacement of the object as time changes
		this.t = 0;           //time
		this.intervalId;      //id used to clearInterval() when time == duration
		this.res;             //callback function must be declared after instance declaration
		
	}
	
	//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	
	Interval.prototype = {		
		setOffset : function(){
			try{
				if(arguments.length != 1){
					throw new Error("Method --> setOffset : Invalid Argument Signature");	
					
				}else{
					this.offset = arguments[0];			
					
				}
				
			}catch(e){
				alert(e.message);	
				
			}
					
		},
	
		//::
					
		getOffset : function(){ 
			return this.offset;	
			
		},
		
		//------------------------------------------
		
		setDisplaceMag : function(){
			try{
				if(arguments.length != 1){
					throw new Error("Method --> setDisplaceMag : Invalid Argument Signature");	
					
				}else{
					this.qm = arguments[0];			
					
				}
				
			}catch(e){
				alert(e.message);	
				
			}
			
		},
		
		//::
		
		getDisplaceMag : function(){
			return this.qm;
			
		},
		
		//------------------------------------------
		
		setDuration : function(){
			try{
				if(arguments.length != 1){
					throw new Error("Method --> setDuration : Invalid Argument Signature");	
					
				}else{
					this.d = arguments[0];			
					
				}
				
			}catch(e){
				alert(e.message);	
				
			}
			
		},
		
		//::
		
		getDuration : function(){ 			
			return this.d;	
			
		},
		
		//------------------------------------------
		
		setFPS : function(){
			try{
				if(arguments.length != 1){
					throw new Error("Method --> setFPS : Invalid Argument Signature");	
					
				}else{
					this.fps = arguments[0];			
					
				}
				
			}catch(e){
				alert(e.message);	
				
			}
			
		},
		
		//::
		
		getFPS : function(){
			return 1000 / this.fps;	
			
		},
		
		//------------------------------------------
		
		setMotionType : function(){ 
			try{
				if(arguments.length != 1){
					throw new Error("Method --> setMotionType : Invalid Argument Signature");	
					
				}else{
					this.motionType = arguments[0];			
					
				}
				
			}catch(e){
				alert(e.message);	
				
			}
			
		},
		
		//::
		
		getMotionType : function(){ 
			return this.motionType;	
			
		},
		
		//------------------------------------------
				
		getVelocity : function(){ 
			return this.qm / this.d;	
			
		},
		
		//------------------------------------------
		
		getDisplacement : function(){ 
			return this.q;	
			
		},
		
		//------------------------------------------
		
		getElapsedTime : function(){ 
			return this.t;
			
		},
			
		//------------------------------------------
		
		startInterval : function(){
			var delegate = this;
			this.intervalId = setInterval(function(){
				delegate.setDisplacement();
						
			}, this.getFPS());
			
		},
		
		//------------------------------------------
			
		setDisplacement : function(){
			this.t++;
			if(this.getElapsedTime() > this.getDuration()){
				this.res("END");
				clearInterval(this.intervalId);
														
			}else{
				switch(this.getMotionType()){
					case "linearMotion":
						this.q = this.getLinearMotion(this.getVelocity(), this.getElapsedTime(), this.getOffset());
						break;
						
					case "quadEaseIn":
						this.q = this.getQuadEaseIn(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getOffset());
						break;
						
					case "quadEaseOut":
						this.q = this.getQuadEaseOut(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getDisplaceMag(), this.getOffset());
						break;
						
					case "cubicEaseIn":
						this.q = this.getCubicEaseIn(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getOffset());
						break;
					
					case "cubicEaseOut":
						this.q = this.getCubicEaseOut(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getDisplaceMag(), this.getOffset());
						break;
					
					case "quarEaseIn":
						this.q = this.getQuarEaseIn(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getOffset());
						break;
						
					case "quarEaseOut":
						this.q = this.getQuarEaseOut(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getDisplaceMag(), this.getOffset());
						break;
				
					case "quinEaseIn":
						this.q = this.getQuinEaseIn(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getOffset());
						break;
						
					case "quinEaseOut":
						this.q = this.getQuinEaseOut(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getDisplaceMag(), this.getOffset());
						break;
					
					case "expEaseIn":
						this.q = this.getExpEaseIn(this.getElapsedTime(), this.getDuration(), this.getDisplaceMag(), this.getOffset());	
						break;
						
					case "expEaseOut":
						this.q = this.getExpEaseOut(this.getElapsedTime(), this.getDisplaceMag(), this.getOffset());
						break;
						
					case "cirEaseIn":
						this.q = this.getCirEaseIn(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getOffset());
						break;
						
					case "cirEaseOut":
						this.q = this.getCirEaseOut(this.getVelocity(), this.getElapsedTime(), this.getDuration(), this.getOffset());
						break;
						
					case "sinMotion":
						this.q = this.getSinMotion(this.getElapsedTime(), this.getDuration(), this.getOffset(), this.getAmplitude(), this.getPeriod());
						break;	
							
				}
				this.res(this.getDisplacement());
				
			}
							
		},
				
		//------------------------------------------
		
		getLinearMotion : function(v, t, b){
			return (v * t) + b;
			
		},
		
		//------------------------------------------
		
		getQuadEaseIn : function(v, t, d, b){
			return ((v * Math.pow(t, 2)) / d) + b;
		
		},
		
		//------------------------------------------
		
		getQuadEaseOut : function(v, t, d, qm, b){
			return (((-v * Math.pow(t - d, 2)) / d) + qm) + b;
		
		},
		
		//------------------------------------------
		
		getCubicEaseIn : function(v, t, d, b){
			return ((v * Math.pow(t, 3)) / Math.pow(d, 2)) + b;
		
		},
		
		//------------------------------------------
		
		getCubicEaseOut : function(v, t, d, qm, b){
			return (((v * Math.pow(t-d, 3)) / Math.pow(d, 2)) + qm) + b;
		
		},
		
		//------------------------------------------
		
		getQuarEaseIn : function(v, t, d, b){
			return ((v * Math.pow(t, 4)) / Math.pow(d, 3)) + b;
		
		},
		
		//------------------------------------------
		
		getQuarEaseOut : function(v, t, d, qm, b){
			return (((-v * Math.pow(t-d, 4)) / Math.pow(d, 3)) + qm) + b;
		
		},
		
		//------------------------------------------
		
		getQuinEaseIn : function(v, t, d, b){
			return ((v * Math.pow(t, 5)) / Math.pow(d, 4)) + b;
		
		},
		
		//------------------------------------------
		
		getQuinEaseOut : function(v, t, d, qm, b){
			return (((v * Math.pow(t-d, 5)) / Math.pow(d, 4)) + qm) + b;
		
		},
		
		//------------------------------------------
	
		getExpEaseIn : function(t, d, qm, b){
			return (qm * Math.pow(2, t-d)) + b;
		
		},
		
		//------------------------------------------
	
		getExpEaseOut : function(t, qm, b){
			return (qm * Math.abs((Math.pow(2, -t) - 1))) + b;
	
		},
		
		//------------------------------------------
	
		getCirEaseIn : function(v, t, d, b){
			return (v * (d - Math.sqrt(Math.pow(d, 2) - Math.pow(t-0, 2)))) + b;
	
		},
		
		//------------------------------------------
	
		getCirEaseOut : function(v, t, d, b){
			return (v * Math.sqrt(Math.pow(d, 2) - Math.pow(t-d, 2))) + b;
	
		},
		
		//------------------------------------------
	
		getSinMotion : function(t, d, b, A, T){
			return A * Math.sin(((T * Math.PI) / d) * t) + b; 
	
		}
				
	}
	
	
	
	