/**
 * The MIT License
 * --------
 * Copyright (c) 2008 ARK-Web
 *
 * 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.
 */

/**
 * @author Satoshi Saito
 *
 * This proguram's easing functions is ported from JSTweener.
 * 
 *   JSTweener - CodeRepos::Share - Trac
 *   http://coderepos.org/share/wiki/JSTweener
 *
 * JSTweener's easing functions is ported from Tweener.
 *
 *   Tweener - Google Code
 *   http://code.google.com/p/tweener/
 */
if (Effect.Transitions) {
    Object.extend(
        Effect.Transitions,
        {
            easeNone: function(pos) {
                return pos;
            },    
            easeInQuad: function(pos) {
                return pos*pos;
            },    
            easeOutQuad: function(pos) {
                return -(pos)*(pos-2);
            },    
            easeInOutQuad: function(pos) {
                if((t=2*pos) < 1) return 0.5*t*t;
                return -0.5 *((--t)*(t-2) - 1);
            },    
            easeInCubic: function(pos) {
                return pos*pos*pos;
            },    
            easeOutCubic: function(pos) {
                return (t=pos-1)*t*t + 1;
            },    
            easeInOutCubic: function(pos) {
                if((t=2*pos) < 1) return 0.5*t*t*t;
                return 0.5*((t-=2)*t*t + 2);
            },    
            easeOutInCubic: function(pos) {
                if(pos < 0.5) return 0.5*Effect.Transitions.easeOutCubic(pos*2);
                return 0.5+0.5*Effect.Transitions.easeInCubic((pos*2)-1);
            },    
            easeInQuart: function(pos) {
                return pos*pos*pos*pos;
            },    
            easeOutQuart: function(pos) {
                return -((t=pos-1)*t*t*t - 1);
            },    
            easeInOutQuart: function(pos) {
                if((t=2*pos) < 1) return 0.5*t*t*t*t;
                return -0.5 *((t-=2)*t*t*t - 2);
            },    
            easeOutInQuart: function(pos) {
                if(pos < 0.5) return 0.5*Effect.Transitions.easeOutQuart(pos*2);
                return 0.5+0.5*Effect.Transitions.easeInQuart((pos*2)-1);
            },    
            easeInQuint: function(pos) {
                return pos*pos*pos*pos*pos;
            },    
            easeOutQuint: function(pos) {
                return (t=pos-1)*t*t*t*t + 1;
            },    
/*
            easeInOutQuint: function(t, b, c, d) {
                if((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
                return c/2*((t-=2)*t*t*t*t + 2) + b;
            },    
            easeOutInQuint: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutQuint(t*2, b, c/2, d);
                return Effect.Transitions.easeInQuint((t*2)-d, b+c/2, c/2, d);
            },    
            easeInSine: function(t, b, c, d) {
                return -c * Math.cos(t/d *(Math.PI/2)) + c + b;
            },    
*/
            easeOutSine: function(pos) {
                return Math.sin(pos *(Math.PI/2));
            },    
            easeInOutSine: function(pos) {
                return -1/2 *(Math.cos(Math.PI*pos) - 1);
            },    
/*
            easeOutInSine: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutSine(t*2, b, c/2, d);
                return Effect.Transitions.easeInSine((t*2)-d, b+c/2, c/2, d);
            },    
*/
            easeInExpo: function(pos) {
                return(pos==0) ? 0 : Math.pow(2, 10 *(pos - 1)) - 0.001;
            },    
            easeOutExpo: function(pos) {
                return(pos==1) ? 1 : 1.001 *(-Math.pow(2, -10 * pos) + 1);
            },    
/*
            easeInOutExpo: function(t, b, c, d) {
                if(t==0) return b;
                if(t==d) return b+c;
                if((t/=d/2) < 1) return c/2 * Math.pow(2, 10 *(t - 1)) + b - c * 0.0005;
                return c/2 * 1.0005 *(-Math.pow(2, -10 * --t) + 2) + b;
            },    
            easeOutInExpo: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutExpo(t*2, b, c/2, d);
                return Effect.Transitions.easeInExpo((t*2)-d, b+c/2, c/2, d);
            },    
*/
            easeInCirc: function(pos) {
                return -(Math.sqrt(1 -pos*pos) - 1);
            },    
            easeOutCirc: function(pos) {
                return Math.sqrt(1 -(t=pos-1)*t);
            },    
/*
            easeInOutCirc: function(t, b, c, d) {
                if((t/=d/2) < 1) return -c/2 *(Math.sqrt(1 - t*t) - 1) + b;
                return c/2 *(Math.sqrt(1 -(t-=2)*t) + 1) + b;
            },    
            easeOutInCirc: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutCirc(t*2, b, c/2, d);
                return Effect.Transitions.easeInCirc((t*2)-d, b+c/2, c/2, d);
            },    
            easeInElastic: function(t, b, c, d, a, p) {
                var s;
                if(t==0) return b;  if((t/=d)==1) return b+c;  if(!p) p=d*.3;
                if(!a || a < Math.abs(c)) { a=c; s=p/4; } else s = p/(2*Math.PI) * Math.asin(c/a);
                return -(a*Math.pow(2,10*(t-=1)) * Math.sin((t*d-s)*(2*Math.PI)/p )) + b;
            },    
            easeOutElastic: function(t, b, c, d, a, p) {
                var s;
                if(t==0) return b;  if((t/=d)==1) return b+c;  if(!p) p=d*.3;
                if(!a || a < Math.abs(c)) { a=c; s=p/4; } else s = p/(2*Math.PI) * Math.asin(c/a);
                return(a*Math.pow(2,-10*t) * Math.sin((t*d-s)*(2*Math.PI)/p ) + c + b);
            },    
            easeInOutElastic: function(t, b, c, d, a, p) {
                var s;
                if(t==0) return b;  if((t/=d/2)==2) return b+c;  if(!p) p=d*(.3*1.5);
                if(!a || a < Math.abs(c)) { a=c; s=p/4; }       else s = p/(2*Math.PI) * Math.asin(c/a);
                if(t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin((t*d-s)*(2*Math.PI)/p )) + b;
                return a*Math.pow(2,-10*(t-=1)) * Math.sin((t*d-s)*(2*Math.PI)/p )*.5 + c + b;
            },    
            easeOutInElastic: function(t, b, c, d, a, p) {
                if(t < d/2) return Effect.Transitions.easeOutElastic(t*2, b, c/2, d, a, p);
                return Effect.Transitions.easeInElastic((t*2)-d, b+c/2, c/2, d, a, p);
            },    
*/
            easeInBack: function(pos, s) {
                if(s == undefined) s = 1.70158;
                return pos*pos*((s+1)*pos - s);
            },    
            easeOutBack: function(pos, s) {
                if(s == undefined) s = 1.70158;
                return (t=pos-1)*t*((s+1)*t + s) + 1;
            },    
/*
            easeInOutBack: function(t, b, c, d, s) {
                if(s == undefined) s = 1.70158;
                if((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
                return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
            },    
            easeOutInBack: function(t, b, c, d, s) {
                if(t < d/2) return Effect.Transitions.easeOutBack(t*2, b, c/2, d, s);
                return Effect.Transitions.easeInBack((t*2)-d, b+c/2, c/2, d, s);
            },    
            easeInBounce: function(t, b, c, d) {
                return c - Effect.Transitions.easeOutBounce(d-t, 0, c, d) + b;
            },    
*/
            easeOutBounce: function(pos) {
                if((pos) <(1/2.75)) {
                    return 7.5625*pos*pos;
                } else if(pos <(2/2.75)) {
                    return 7.5625*(pos-=(1.5/2.75))*pos + .75;
                } else if(pos <(2.5/2.75)) {
                    return 7.5625*(pos-=(2.25/2.75))*pos + .9375;
                } else {
                    return 7.5625*(pos-=(2.625/2.75))*pos + .984375;
                }
            }
/*,    
            easeInOutBounce: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeInBounce(t*2, 0, c, d) * .5 + b;
                else return Effect.Transitions.easeOutBounce(t*2-d, 0, c, d) * .5 + c*.5 + b;
            },    
            easeOutInBounce: function(t, b, c, d) {
                if(t < d/2) return Effect.Transitions.easeOutBounce(t*2, b, c/2, d);
                return Effect.Transitions.easeInBounce((t*2)-d, b+c/2, c/2, d);
            }
*/
            
        }); 
}
