/** 
 * Easing Equations for Script.aculo.us originally created by
 * Brian Crescimanno <http://briancrescimanno.com>.  
 * Expanded by Brett Lavalla.
 *
 * @author Brian Crescimanno <brian.crescimanno@gmail.com>
 * @author Brett Lavalla <blavalla@gmail.com>
 * @version 1.0
 * @revised February 10, 2009
 * @copyright 2009 Brett Lavalla, all rights reserved
 *
 * Released under terms of the BSD License
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * The math for these equations was created by Robert Penner
 * http://www.robertpenner.com/profmx
 * 
**/
  
/****** Quadratic ******/

Effect.Transitions.easeInQuad = function(pos){
	return Math.pow(pos, 2);
}

Effect.Transitions.easeOutQuad = function(pos){
	return -(Math.pow((pos-1), 2) -1);
}

Effect.Transitions.easeInOutQuad = function(pos){
	if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,2);
    return -0.5 * ((pos-=2)*pos - 2); 
}

/****** Cubic ******/

Effect.Transitions.easeInCubic = function(pos){
	return Math.pow(pos, 3);
}

Effect.Transitions.easeOutCubic = function(pos){
	return (Math.pow((pos-1), 3) +1);
}

Effect.Transitions.easeInOutCubic = function(pos){
	if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,3);
    return 0.5 * (Math.pow((pos-2),3) + 2); 	
}

/****** Quartic ******/

Effect.Transitions.easeInQuart = function(pos){
	return Math.pow(pos, 4);
}

Effect.Transitions.easeOutQuart = function(pos){
	return -(Math.pow((pos-1), 4) -1)
}

Effect.Transitions.easeInOutQuart = function(pos){
	if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,4);
    return -0.5 * ((pos-=2)*Math.pow(pos,3) - 2); 
}

/****** Quintic ******/

Effect.Transitions.easeInQuint = function(pos){
	return Math.pow(pos, 5);
}

Effect.Transitions.easeOutQuint = function(pos){
	return (Math.pow((pos-1), 5) +1);
}

Effect.Transitions.easeInOutQuint = function(pos){
	if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,5);
    return 0.5 * (Math.pow((pos-2),5) + 2); 	
}

/****** Sinusoidal ******/

Effect.Transitions.easeInSine = function(pos){
	return -Math.cos(pos * (Math.PI/2)) + 1;
}

Effect.Transitions.easeOutSine = function(pos){
	return Math.sin(pos * (Math.PI/2));
}

Effect.Transitions.easeInOutSine = function(pos){
	return (-.5 * (Math.cos(Math.PI*pos) -1));
}

/****** Exponential ******/

Effect.Transitions.easeInExpo = function(pos){
	return (pos==0) ? 0 : Math.pow(2, 10 * (pos - 1));
}

Effect.Transitions.easeOutExpo = function(pos){
	return (pos==1) ? 1 : -Math.pow(2, -10 * pos) + 1;
}

Effect.Transitions.easeInOutExpo = function(pos){
	if(pos==0) return 0;
	if(pos==1) return 1;
	if((pos/=0.5) < 1) return 0.5 * Math.pow(2,10 * (pos-1));
	return 0.5 * (-Math.pow(2, -10 * --pos) + 2);	
}

/****** Circular ******/

Effect.Transitions.easeInCirc = function(pos){
	return -(Math.sqrt(1 - (pos*pos)) - 1);
}

Effect.Transitions.easeOutCirc = function(pos){
	return Math.sqrt(1 - Math.pow((pos-1), 2))
}

Effect.Transitions.easeInOutCirc = function(pos){
	if((pos/=0.5) < 1) return -0.5 * (Math.sqrt(1 - pos*pos) - 1);
	return 0.5 * (Math.sqrt(1 - (pos-=2)*pos) + 1);	
}

/****** Bounce ******/

Effect.Transitions.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);
	}
}

Effect.Transitions.easeInBounce = function(pos){
	var value;
	for (var a = 0, b = 1; 1; a += b, b /= 2){
		if (pos >= (7 - 4 * a) / 11){
			value = - Math.pow((11 - 6 * a - 11 * pos) / 4, 2) + b * b;
			break;
		}
	}
	return value;
}

Effect.Transitions.easeInOutBounce = function(pos){
	if(pos<= 0.5){
		pos = 2* pos;
		var value;
		for (var a = 0, b = 1; 1; a += b, b /= 2){
			if (pos >= (7 - 4 * a) / 11){
				value = - Math.pow((11 - 6 * a - 11 * pos) / 4, 2) + b * b;
				break;
			}
		}
		return value/2;
	} else {
		pos = 2*(1-pos);
		var value;
		for (var a = 0, b = 1; 1; a += b, b /= 2){
			if (pos >= (7 - 4 * a) / 11){
				value = - Math.pow((11 - 6 * a - 11 * pos) / 4, 2) + b * b;
				break;
			}
		}
		return 1-(value)/2;
	}
}

/****** Back ******/

Effect.Transitions.easeInBack = function(pos){
	var s = 1.70158;	
	return (pos)*pos*((s+1)*pos - s);
}

Effect.Transitions.easeOutBack = function(pos){
	var s = 1.70158;	
	return (pos=pos-1)*pos*((s+1)*pos + s) + 1;
}

Effect.Transitions.easeInOutBack = function(pos){
	var s = 1.70158;	
	if((pos/=0.5) < 1) return 0.5*(pos*pos*(((s*=(1.525))+1)*pos -s));
	return 0.5*((pos-=2)*pos*(((s*=(1.525))+1)*pos +s) +2);
}

/****** Elastic ******/

Effect.Transitions.easeInElastic = function(pos){
	return Math.pow(2, 10 * --pos) * Math.cos(20 * pos * Math.PI * (1) / 3);
}

Effect.Transitions.easeOutElastic = function(pos){
	pos = 1 - pos;
	return 1-(Math.pow(2, 10 * --pos) * Math.cos(20 * pos * Math.PI * (1) / 3));
}

Effect.Transitions.easeInOutElastic = function(pos){	
	if(pos<= 0.5){
		pos = 2* pos;
		return (Math.pow(2, 10 * --pos) * Math.cos(20 * pos * Math.PI * (1) / 3))/2;
	} else {
		pos = 2*(1-pos);
		return 1-(Math.pow(2, 10 * --pos) * Math.cos(20 * pos * Math.PI * (1) / 3)/2);
	}
}

