// ============================================================================================
//  based on
//  Easing Equations v2.0
//  September 1, 2003
//  (c) 2003 Robert Penner, all rights reserved. 
//  This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html.
// ============================================================================================

/////////// Back Easing: overshooting cubic easing: (a+1)*p^3 - a*p^2  //////////////
Effect.Transitions.Back = {
	easeIn: function(p, a) {
		if (a == null) {
			a = 1.70158
		}
		return p * p * ((a + 1) * p - a)
	},
	easeOut: function(p, a) {
		if (a == null) {
			a = 1.70158
		}
		p -= 1
		return p * p * ((a + 1) * p + a) + 1
	},
	easeInOut: function(p, a) {
		if (a == null) {
			a = 1.70158
		}
		p *= 2
		a *= 1.525
		if (p < 1) {
			return p * p * ((a + 1) * p - a) / 2
		} else {
			p -= 2
			return (p * p * ((a + 1) * p + a) + 2) / 2
		}
	}
}
/////////// Bounce Easing: exponentially decaying parabolic bounce  //////////////
Effect.Transitions.Bounce = {
	easeIn: function(p) {
		return 1 - Effect.Transitions.Bounce.easeOut(1 - p)
	},
	easeOut: function(p) {
		if (p < 1 / 2.75) {
			return 7.5625 * p * p
		} else if (p < 2 / 2.75) {
			return 7.5625 * (p -= 1.5 / 2.75) * p + 0.75
		} else if (p < (2.5/2.75)) {
			return 7.5625 * (p -= 2.25 / 2.75) * p + 0.9375
		} else {
			return 7.5625 * (p -= 2.625 / 2.75) * p + 0.984375
		}
	},
	easeInOut: function(p) {
		if (p < 0.5) {
			return Effect.Transitions.Bounce.easeIn(p * 2) / 2
		} else {
			return Effect.Transitions.Bounce.easeOut(p * 2 - 1) / 2 + 0.5
		}
	}
}
/////////// Circular Easing: sqrt(1-p^2) //////////////
Effect.Transitions.Circ = {
	easeIn: function(p) {
		return 1 - Math.sqrt(1 - Math.pow(p, 2))
	},
	easeOut: function(p) {
		return 1 * Math.sqrt(1 - Math.pow(p - 1, 2))
	},
	easeInOut: function(p) {
		if (p < 0.5) {
			return (1 - Math.sqrt(1 - Math.pow(p * 2, 2))) / 2
		} else {
			return (Math.sqrt(1 - Math.pow(p * 2 - 2, 2)) + 1) / 2
		}
	}
}
/////////// Elastic Easing: exponentially decaying sine wave  //////////////
Effect.Transitions.Elastic = {
	easeIn: function(p, a, b) {
		if (p == 0) {
			return 0
		} else if (p == 1) {
			return 1
		} else {
			if (!b) {
				b = 0.3
			}
			if (!a || a < 1) {
				a = 1
				var s = b / 4
			} else {
				var s = b / (2 * Math.PI) * Math.asin(1 / a)
			}
			p -= 1
			return -(a * Math.pow(2, 10 * p) * Math.sin((p - s) * 2 * Math.PI / b))
		}
	},
	easeOut: function(p, a, b) {
		if (p == 0) {
			return 0
		} else if (p == 1) {
			return 1
		} else {
			if (!b) {
				b = 0.3
			}
			if (!a || a < 1) {
				a = 1
				var s = b / 4
			} else {
				var s = b / (2 * Math.PI) * Math.asin(1 / a)
			}
			return a * Math.pow(2, -10 * p) * Math.sin((p - s) * 2 * Math.PI / b) + 1
		}
	},
	easeInOut: function(p, a, b) {
		if (p == 0) {
			return 0
		} else if (p == 1) {
			return 1
		} else {
			if (!b) {
				b = 0.3 * 1.5
			}
			if (!a || a < 1) {
				a = 1
				var s = b / 4
			} else {
				var s = b / (2 * Math.PI) * Math.asin(1 / a)
			}

			p = p * 2 - 1
			if (p < 0) {
				return a * Math.pow(2, 10 * p) * Math.sin((p - s) * 2 * Math.PI / b) / -2
			} else {
				return a * Math.pow(2, -10 * p) * Math.sin((p - s) * 2 * Math.PI / b) / 2 + 1
			}
		}
	}
}
///////////// Exponential Easing: 2^p /////////////////
Effect.Transitions.Expo = {
	easeIn: function(p) {
		return (p == 0) ? 0 : Math.pow(2, 10 * (p - 1))
	},
	easeOut: function(p) {
		return (p == 1) ? 1 : 1 - Math.pow(2, -10 * p)
	},
	easeInOut: function(p) {
		if (p == 0) {
			return 0
		} else if (p == 1) {
			return 1
		} else if (p < 0.5) {
			return Math.pow(2, 10 * (p * 2 - 1)) / 2
		} else {
			return (2 - Math.pow(2, -10 * (p * 2 - 1))) / 2
		}
	}
}

///////////// Quadratic Easing: p^2 ///////////////////
Effect.Transitions.Quad = {
	easeIn: function(p) {
		return Math.pow(p, 2)
	},
	easeOut: function(p) {
		return 1 - Math.pow(p - 1, 2)
	},
	easeInOut: function(p) {
		return (p < 0.5 ? Math.pow(p * 2, 2) : 2 - Math.pow(p * 2 - 2, 2)) / 2
	}
}

///////////// Cubic Easing: p^3 ///////////////////////
Effect.Transitions.Cubic = {
	easeIn: function(p) {
		return Math.pow(p, 3)
	},
	easeOut: function(p) {
		return 1 + Math.pow(p - 1, 3)
	},
	easeInOut: function(p) {
		return (p < 0.5 ? Math.pow(p * 2, 3) : 2 + Math.pow(p * 2 - 2, 3)) / 2
	}
}

///////////// Quartic Easing: p^4 /////////////////////
Effect.Transitions.Quart = {
	easeIn: function(p) {
		return Math.pow(p, 4)
	},
	easeOut: function(p) {
		return 1 - Math.pow(p - 1, 4)
	},
	easeInOut: function(p) {
		return (p < 0.5 ? Math.pow(p * 2, 4) : 2 - Math.pow(p * 2 - 2, 4)) / 2
	}
}

// Quintic Easing: p^5
Effect.Transitions.Quint = {
	easeIn: function(p) {
		return Math.pow(p, 5)
	},
	easeOut: function(p) {
		return 1 + Math.pow(p - 1, 5)
	},
	easeInOut: function(p) {
		return (p < 0.5 ? Math.pow(p * 2, 5) : 2 + Math.pow(p * 2 - 2, 5)) / 2
	}
}

// Sinusoidal Easing: sin(p)
Effect.Transitions.Sine = {
	easeIn: function(p) {
		return 1 - Math.cos(p * Math.PI / 2)
	},
	easeOut: function(p) {
		return Math.sin(p * Math.PI / 2)
	},
	easeInOut: function(p) {
		return (1 - Math.cos(Math.PI * p)) / 2
	}
}
