//------------------------------------------------------------------------------------------
// LIBRARY: 
// Veer.Animation
//
// DESCRIPTION:
// Implements Robert Penner's animation easing equations in JavaScript. Note that this is
// not a full fledged animation library yet. This class merely host's easing equations.
//
// REQUIRED HEAD TAGS:
// <script type="text/javascript" language="javascript" src="<%= IncludeUri.Path %>/veer.animation.js"></script>
//
// DEPENDENCIES:
// None.
//
// NOTES:
// All easing equations take four parameters:
// t - the current time, as represented by a number from 0 to d
// b - the begining position
// c - the change is position as t runs to d from 0
// d - the total duration of the easing
//
// Note that these equations do not take the ending position, they take the change in
// position. So an object that is to start at 10 and end at 40, has a change in position
// of 30.
//
// Note that t must run from 0 to d. So whatever method is being used to determine time,
// must have t=0 as the start of the easing, and t=d at the end of the easing. Negative t
// will cause funkiness.
//------------------------------------------------------------------------------------------
 
 
if (typeof(Veer) == 'undefined') {
    Veer = {};
}
 
// The animation system will exist at this level, some day.
 
if (typeof(Veer.Animation) == 'undefined') {
    Veer.Animation = {};
}
 
//----- ANIMATION EASING EQUATIONS ---------------------------------------------------------
 
if (typeof(Veer.Animation.Easing) == 'undefined') {
    Veer.Animation.Easing = {};
}
 
//----- ANIMATION EASING EQUATIONS -- BACK EASING ------------------------------------------
 
Veer.Animation.Easing.Back = { };
 
Veer.Animation.Easing.Back.easeIn = function(t, b, c, d) {
	if (s == undefined) s = 1.70158;
	return c*(t/=d)*t*((s+1)*t - s) + b;
};
	
Veer.Animation.Easing.Back.easeOut = function(t, b, c, d) {
	if (s == undefined) s = 1.70158;
	return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
};
 
Veer.Animation.Easing.Back.easeInOut = function(t, b, c, d) {
	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;
};
 
//----- ANIMATION EASING EQUATIONS -- BOUNCE EASING ------------------------------
 
Veer.Animation.Easing.Bounce = { };
 
Veer.Animation.Easing.Bounce.easeOut = function(t, b, c, d) {
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
	}
};
	
Veer.Animation.Easing.Bounce.easeIn = function(t, b, c, d) {
	return c - Veer.Animation.Easing.Bounce.easeOut (d-t, 0, c, d) + b;
};
	
Veer.Animation.Easing.Bounce.easeInOut = function(t, b, c, d) {
	if (t < d/2) return Veer.Animation.Easing.Bounce.easeIn (t*2, 0, c, d) * 0.5 + b;
	else return Veer.Animation.Easing.Bounce.easeOut (t*2-d, 0, c, d) * 0.5 + c*0.5 + b;
};
 
//----- ANIMATION EASING EQUATIONS -- CIRCULAR EASING ----------------------------
 
Veer.Animation.Easing.Circ = { };
 
Veer.Animation.Easing.Circ.easeIn = function(t, b, c, d) {
	return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
};
 
Veer.Animation.Easing.Circ.easeOut = function(t, b, c, d) {
	return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
};
 
Veer.Animation.Easing.Circ.easeInOut = 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;
};
 
//----- ANIMATION EASING EQUATIONS -- CUBIC EASING -------------------------------
 
Veer.Animation.Easing.Cubic = { };
 
Veer.Animation.Easing.Cubic.easeIn = function(t, b, c, d) {
	return c*(t/=d)*t*t + b;
};
 
Veer.Animation.Easing.Cubic.easeOut = function(t, b, c, d) {
	return c*((t=t/d-1)*t*t + 1) + b;
};
 
Veer.Animation.Easing.Cubic.easeInOut = function(t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
};
 
//----- ANIMATION EASING EQUATIONS -- ELASTIC EASING -----------------------------
 
Veer.Animation.Easing.Elastic = { };
 
Veer.Animation.Easing.Elastic.easeIn = function(t, b, c, d) {
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*0.3;
	if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	else var 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;
};
	
Veer.Animation.Easing.Elastic.easeOut = function(t, b, c, d) {
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*0.3;
	if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	else var 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);
};
	
Veer.Animation.Easing.Elastic.easeInOut = function(t, b, c, d) {
	if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(0.3*1.5);
	if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	if (t < 1) return -0.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 )*0.5 + c + b;
};
 
//----- ANIMATION EASING EQUATIONS -- EXPONENTIAL EASING -------------------------
 
Veer.Animation.Easing.Expo = { };
 
Veer.Animation.Easing.Expo.easeIn = function(t, b, c, d) {
	return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
};
 
Veer.Animation.Easing.Expo.easeOut = function(t, b, c, d) {
	return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
};
 
Veer.Animation.Easing.Expo.easeInOut = 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;
	return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
};
 
//----- ANIMATION EASING EQUATIONS -- LINEAR EASING ------------------------------
 
Veer.Animation.Easing.Linear = { };
 
Veer.Animation.Easing.Linear.easeNone = function(t, b, c, d) {
	return c*t/d + b;
};
 
Veer.Animation.Easing.Linear.easeIn = function(t, b, c, d) {
	return c*t/d + b;
};
 
Veer.Animation.Easing.Linear.easeOut = function(t, b, c, d) {
	return c*t/d + b;
};
 
Veer.Animation.Easing.Linear.easeInOut = function(t, b, c, d) {
	return c*t/d + b;
};
 
//----- ANIMATION EASING EQUATIONS -- QUADRATIC EASING ---------------------------
 
Veer.Animation.Easing.Quad = { };
 
Veer.Animation.Easing.Quad.easeIn = function(t, b, c, d) {
	return c*(t/=d)*t + b;
};
 
Veer.Animation.Easing.Quad.easeOut = function(t, b, c, d) {
	return -c *(t/=d)*(t-2) + b;
};
 
Veer.Animation.Easing.Quad.easeInOut = function(t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
};
 
//----- ANIMATION EASING EQUATIONS -- QUART EASING -------------------------------
 
Veer.Animation.Easing.Quart = { };
 
Veer.Animation.Easing.Quart.easeIn = function(t, b, c, d) {
	return c*(t/=d)*t*t*t + b;
};
 
Veer.Animation.Easing.Quart.easeOut = function(t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
 
Veer.Animation.Easing.Quart.easeInOut = function(t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
	return -c/2 * ((t-=2)*t*t*t - 2) + b;
};
 
//----- ANIMATION EASING EQUATIONS -- QUINT EASING -------------------------------
 
Veer.Animation.Easing.Quint = { };
 
Veer.Animation.Easing.Quint.easeIn = function(t, b, c, d) {
	return c*(t/=d)*t*t*t*t + b;
};
 
Veer.Animation.Easing.Quint.easeOut = function(t, b, c, d) {
	return c*((t=t/d-1)*t*t*t*t + 1) + b;
};
 
Veer.Animation.Easing.Quint.easeInOut = 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;
};
 
//----- ANIMATION EASING EQUATIONS -- SINE EASING --------------------------------
 
Veer.Animation.Easing.Sine = { };
 
Veer.Animation.Easing.Sine.easeIn = function(t, b, c, d) {
	return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
};
	
Veer.Animation.Easing.Sine.easeOut = function(t, b, c, d) {
	return c * Math.sin(t/d * (Math.PI/2)) + b;
};
	
Veer.Animation.Easing.Sine.easeInOut = function(t, b, c, d) {
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
};
