/**
 * 
 * joink.FX:			Javascript bezier motion class
 * 
 * @Author				Jochen Vandendriessche
 * @Contact				info@joggink.be
 * @classDescription	This class uses the Robert-Penner beziers animation formulas
 * 						You can generate your functions at
 * 						http://timotheegroleau.com/Flash/experiments/easing_function_generator.htm
 * 						Have fun playin' around, docs are coming real soon...
 * @version				0.21b
 * @build				2007 06 28 12 08
 * @License				MIT licence
 * 
 * Copyright (c) 2007, Jochen Vandendriessche
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 */

function joinkFX(obj, type, time, dir, start, dist, bi){
    this.obj = obj;
    this.cnt = 0;
    if (time){
        this.time = time;
    }else{
        this.time = 50;
    }
    this.type = this[type];
    this.active = false;
    this.dir = dir.toString().split(',');
    this.start = start.toString().split(',');
    this.dist = dist.toString().split(',');
    this.func = '';
	this.bi = false;
	if (bi){
		this.bi = true;
	}
}

joinkFX.prototype = {
    
    setFunc			:		function(func){
                                this.func = func;	
    }
    
    ,
    
    setStart		:		function(start){
                                this.start = start.toString().split(',');	
    }
    
    ,
    
    setDist		:		function(dist){
                                this.dist = dist.toString().split(',');
    }
    
    ,
    
    setType		:		function(type){
                                this.type = this[type];
    }
    
    ,
    
    move			:		function(){
                                    if (this.cnt <= this.time){
                                        this.active = true;
                                        var newPos = 0;
                                        for (var i = 0;i<this.start.length;i++){
                                            newPos = this.type(this.cnt, parseInt(this.start[i]), parseInt(this.dist[i]), this.time);
//											window.alert(newPos);											
                                            this.obj.style[this.dir[i]] = Math.ceil(newPos) + 'px';
                                        }
                                        this.cnt++;
                                        window.setTimeout(bind(this, this.move), 15);
                                    }else{
                                        if (this.func){
                                            this.func.call();
                                        }
										if (this.bi){
											for (var i = 0;i<this.start.length;i++){
												this.start[i] = parseInt(this.start[i]) + parseInt(this.dist[i]);
												this.dist[i] = 0 - parseInt(this.dist[i]);
											}
										}
                                        this.cnt = 0;
                                        this.active = false;
                                    }
    }
    
	,
	
	bounceSmall	:		function(t, b, c, d){
								var ts=(t/=d)*t;
								var tc=ts*t;
								return b+c*(36.4925*tc*ts + -106.88*ts*ts + 116.48*tc + -57.79*ts + 12.6975*t);		
	}
	
	,
	
	bounceBig	:		function(t, b, c, d){
								var ts=(t/=d)*t;
								var tc=ts*t;
								return b+c*(78.1425*tc*ts + -216.88*ts*ts + 217.88*tc + -94.69*ts + 16.5475*t);	
	}
	
    ,
    
    noEase		:		function(t, b, c, d){
                                t/=d;
                                return b+c*(t);
    }
    
    ,
    
    backInCubic	:		function(t, b, c, d){
                                var ts = (t/=d)*t;
                                var tc = ts*t;
                                return b+c*(4*tc + -3*ts);		
    }

    ,
    
    outElasticSmall:	function(t, b, c, d){
                                var ts =(t/=d)*t;
                                var tc =ts*t;
                                return b+c*(33*tc*ts + -106*ts*ts + 126*tc + -67*ts + 15*t);
    }
    
    ,
    
    outElasticBig	:	function(t, b, c, d){
                                var ts = (t/=d)*t;
                                var tc = ts*t;
                                return b+c*(56*tc*ts + -175*ts*ts + 200*tc + -100*ts + 20*t);		
    }

    ,

    inQuintic		:	function(t, b, c, d){
                                var ts = (t/=d)*t;
                                var tc = ts*t;
                                return b+c*(tc*ts);		
    }
    
    ,

    outQuintic		:	function(t, b, c, d){
                                var ts = (t/=d)*t;
                                var tc = ts*t;
                                return b+c*(tc*ts + -5*ts*ts + 10*tc + -10*ts + 5*t);		
    }
    
    ,

    outCubic			:	function(t, b, c, d){
                                var ts = (t/=d)*t;
                                var tc = ts*t;
                                return b+c*(tc + -3*ts + 3*t);		
    }

}

function bind(el, func){
    return function() { func.call(el); }
}