/*
 * jQuery Easing v1.0b - http://gsgd.co.uk/sandbox/jquery.easing.php
 *
 * Copyright (c) 2006 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */

jQuery.speed = function (s,o) {
		o = o || {};
		
		if ( o.constructor == Function )
			o = { complete: o };
		var ss = { slow: 600, fast: 200 };
		if (s && s.constructor == Object) {
			o.easeMethod = s.easeMethod || 'inout';
			s = s.duration;
		}	else {
			o.easeMethod = 'easeout';
		}
		o.duration = (s && s.constructor == Number ? s : ss[s]) || 400;
		// Queueing
		o.oldComplete = o.complete;
		o.complete = function(){
			jQuery.dequeue(this, "fx");
			if ( o.oldComplete && o.oldComplete.constructor == Function )
				o.oldComplete.apply( this );
		};
	
		return o;
}
// rewrite the fx function to add in the easeMethod to the options object. Need to convert to string
// seemed shorter than rewriting the whole function, and should help prevent changes to jquery causing problems.
// alert(String(jQuery.fx).match(RegExp("z.o = \\{[^}]+\\};"))); 
jQuery.fx = String(jQuery.fx).replace(RegExp("z.o = \\{[^}]+\\};"), 
'z.o = {\
		duration: options.duration || 400,\
		complete: options.complete,\
		step: options.step,\
		easeMethod: options.easeMethod\
	};');
// rewrite the fx function to add in the easing to the options step function
// 100 * in is to prevent problems with expo for numbers between 0 and 1.  Might as well round objects to 2dp while we're at it. 
jQuery.fx = String(jQuery.fx).replace(RegExp("var p = [^}]+"), 
'var p = (t - z.startTime);\
z.now = (firstNum < lastNum) \
? 100*firstNum + jQuery.easing(p, 0, 100*(lastNum - firstNum), z.o.duration, z.o.easeMethod) \
: 100*firstNum - jQuery.easing(p, 0, 100*(firstNum - lastNum), z.o.duration, z.o.easeMethod);\
z.now = Math.round(z.now)/100;\
z.a();');


// make it a Function again
jQuery.fx = Function( "elem", "options", "prop", jQuery.fx.substring(jQuery.fx.indexOf('{')+1, jQuery.fx.lastIndexOf('}')));

jQuery.easing = function(t, b, c, d, type) {
/* Easing Equations ported from Robert Penner's Actionscript Equations
 * (c) 2003 Robert Penner, all rights reserved. 
 * This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html.
 * t = current time b = start value c = end value d = duration
 */
	var e;
	if (type.constructor == Function) {
		e = type;
	} else {
		e = jQuery.equations[type];
	}
	// alert(e.constructor);
	if (!e || e.constructor != Function) {
		e = jQuery.equations['easeinout'];
	}
	return e(t,b,c,d);
}
jQuery.equations = {
	easein: function(t, b, c, d) {
		return c*(t/=d)*t + b; // in
	},
	easeinout: function(t, b, c, d) {
		if (t < d/2) return 2*c*t*t/(d*d) + b;
		var ts = t - d/2;
		return -2*c*ts*ts/(d*d) + 2*c*ts/d + c/2 + b;		
	},
	easeout: function(t, b, c, d) {
		return -c*t*t/(d*d) + 2*c*t/d + b;
	}
}
