//
// Based on Easing Equations v2.0
// (c) 2003 Robert Penner, all rights reserved. 
// OPEN-SOURCE TERMS OF USE: http://www.robertpenner.com/easing_terms_of_use.html
// Adapted for Scriptaculous by Ken Snyder (kendsnyder.com) June 2006
//

//
// Overshooting Transitions
//

// Elastic (adapted from "EaseOutElastic")
// using global variables as options:
// trnsp.options.friction = "friction"
// trnsp.options.decel = "deceleration"
// trnsp.options.bounce = "bounce"
Effect.Transitions.Elastic = function(pos) {
	return (-1*Math.pow(trnsp.options.friction,-1*trnsp.options.decel*pos) * Math.sin( (pos*trnsp.options.bounce-1)*(2*Math.PI)/2 ) + 0.5) + 0.5;
};
// SwingFromTo (adapted from "BackEaseInOut")
Effect.Transitions.SwingFromTo = 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);
};
// SwingFrom (adapted from "BackEaseIn")
Effect.Transitions.SwingFrom = function(pos) {
	var s = 1.70158;
	return pos*pos*((s+1)*pos - s);
};
// SwingTo (adapted from "BackEaseOut")
Effect.Transitions.SwingTo = function(pos) {
	var s = 1.70158;
	return (pos-=1)*pos*((s+1)*pos + s) + 1;
};

//
// Bouncing Transitions
//

// Bounce (adapted from "EaseOutBounce")
Effect.Transitions.Bounce = 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);
	}
};
// BouncePast (new creation based on "EaseOutBounce")
Effect.Transitions.BouncePast = function(pos) {
	if (pos < (1/2.75)) {
		return (7.5625*pos*pos);
	} else if (pos < (2/2.75)) {
		return 2 - (7.5625*(pos-=(1.5/2.75))*pos + .75);
	} else if (pos < (2.5/2.75)) {
		return 2 - (7.5625*(pos-=(2.25/2.75))*pos + .9375);
	} else {
		return 2 - (7.5625*(pos-=(2.625/2.75))*pos + .984375);
	}
};

//
// Gradual Transitions
//

// EaseFromTo (adapted from "EaseInOut")
// using global variables as options:
// trnsp.options.easing = exponent
Effect.Transitions.EaseFromTo = function(pos) {
	switch( Math.round(trnsp.options.easing) ) {
		case 5:
			if ((pos/=0.5) < 1) return 0.5*pos*pos*pos*pos*pos;
			return 0.5*((pos-=2)*pos*pos*pos*pos + 2);		
		case 4:
			if ((pos/=0.5) < 1) return 0.5*pos*pos*pos*pos;
			return -0.5 * ((pos-=2)*pos*pos*pos - 2);	
		case 3:
			if ((pos/=0.5) < 1) return 0.5*pos*pos*pos;
			return 0.5*((pos-=2)*pos*pos + 2);		
		case 2:
		default:
			if ((pos/=0.5) < 1) return 0.5*pos*pos;
			return -0.5 * ((pos-=1)*(pos-2) - 1);	
	}
};
// EaseFrom (adapted from"EaseIn")
// using global variables as options:
// trnsp.options.easing = exponent
Effect.Transitions.EaseFrom = function(pos) {
	return Math.pow(pos,trnsp.options.easing);
};
// EaseTo (adapted from "EaseOut")
// using global variables as options:
// trnsp.options.easing = exponent
Effect.Transitions.EaseTo = function(pos) {
	return Math.pow(pos,1/trnsp.options.easing);
};