var $j = jQuery.noConflict();
var selectedIndex = 0;     
jQuery.easing.def = "easeOutBounce";
    
     
$j(document).ready(function(){
	
	initNavigation();
	initForms();
	initEqualHeight();
	initAuthors();
	initStockists();
	initPopupGallery();
	
});

$j(window).load(function(){
	initHomepage();
	initGalleryHeight();
});

function initPopupGallery(){

	$j("#DISABLEDphotos a:first").click(function(e){
		e.preventDefault();
		var link = $j(this).attr('href');
		if($j("#photos .icon_zoom").length > 0){
			$j("#photos .icon_zoom").trigger('click');
		} else {
			window.open(link,"LargeImage","menubar=no,width=600,height=auto,toolbar=no");
		}
		
	});
	
	//var images = $j("#photos_small img");
	//if(images.length <= 3){
		$j("#popup .controls").hide();
	//}
	
	$j("#popup .scroll_left").click(function(e){
		e.preventDefault();
	
	});
	
	$j("#popup .scroll_right").click(function(e){
		e.preventDefault();
	
	});
	
	$j("#photos_small img").click(function(e){
	
		e.preventDefault();
		var link = $j(this).attr('longdesc');
		var clone = "<a title='Click for full view' href='" + link + "' target='_blank'><img src='" + link + "' /></a>";
		$j("#photos_large").html(clone);
		$j("#photos_small img").removeClass('active');
		$j(this).addClass('active');
		
		updatePaginator();
		
	});
	
	$j("#photos_small img:first").trigger('click');
	
	$j("#detail_back").click(function(e){
		e.preventDefault();
		var selected = parseInt($j("#page_current").text());
		
		if(selected == 1){
			index = $j("#photos_small .photo img").length - 1;
		} else {
			index = selected - 1;
		}
		
		$j("#photos_small .photo img:eq(" + index + ")").trigger('click');
		
	});
	
	$j("#detail_forward").click(function(e){
		e.preventDefault();
		
		var selected = parseInt($j("#page_current").text());
		
		if(selected == $j("#photos_small .photo img").length){
			index = 0;
		} else {
			index = selected;
		}
		
		$j("#photos_small .photo img:eq(" + index + ")").trigger('click');
		
	});
	
}

function initGalleryHeight(){

	var largest = 0;
	
	$j("#photos_small .photo img").each(function(){
		
		if($j(this).height() > largest){
			largest = $j(this).height();
		}
		
	});
	
	$j("#photos_small .photo img").each(function(){
		
		if($j(this).height() < largest){
			var height = 0.5 * (largest - $j(this).height());
			$j(this).parents('.photo').css('padding-top', height);
			$j(this).parents('.photo').css('padding-bottom', height);
		}
		
	});

}

function updatePaginator(){
	
	$j("#page_total").text($j("#photos_small .photo img").length);
	
	$j("#photos_small .photo img").each(function(i){
		if($j(this).hasClass('active')){
			$j("#page_current").text(i+1);
		}
	});
}


function initStockists(){
	
	var stockists = $j(".stockist");
	var per_column = parseInt(stockists.length / 3);
	
	var first_column = per_column;
	var second_column = 2 * per_column;
	
	/*
$j(".uparent_7 #content").append("<div class='stockists_column' id='col1'></div>");
	$j(".uparent_7 #content").append("<div class='stockists_column' id='col2'></div>");
	$j(".uparent_7 #content").append("<div class='stockists_column' id='col3'></div>");
*/
	var biggest = 0;
	var table = "<table id='stockist_table' style='clear: both'>";
	$j(stockists).each(function(i){
		if(i % 3 == 0){
			table += "<tr>";
		}
		
		table += "<td>" + $j(this).html() + "</td>"
		
		if(i % 3 == 2 || i+1 == stockists.length ){
			table += "</tr>";
		}
		
		/*
if(i <= first_column) {
			$j("#col1").append($j(this));
		} else if (i <= second_column){
			$j("#col2").append($j(this));
		} else {
			$j("#col3").append($j(this));
		}
		var height = $j(this).height();
		if(height > biggest){
			biggest = height;
		}
*/
		

	});
	
	table += "</table>";
	$j(".uparent_7 #content").html(table);
	
	$j(stockists).height(biggest);
	
}

function initAuthors(){
	
}


function initEqualHeight(){
	if($j("#content").height() < 400){
		
		if($j("#content").hasClass('cart')){
		
		} else {
			$j("#content").height(400);
		}
		
	}
	
	if($j("#book_details").height() < 300){
		$j("#book_details").height(300);
	}
}

var docDirty = false;

function doCheckout(){
	
	$j("#cart_form").attr('action', 'https://www.2checkout.com/checkout/purchase');
	$j("#cart_form").submit();
	
}

function initForms(){
	$j("#empty_cart td").hide();
	//$j("#mailing_list_form").validate();
	//$j("#contact_form").validate();
	
	$j("#add_book_to_cart").click(function(e){
		/* e.preventDefault(); */
	});
	
	$j("#change_currencies").change(function(e){
		window.location.href = window.location.href + "?&currency=" + $j(this).val();
	});
	
	$j(".quantity").change(function(e){
		docDirty = true;
	});
	
	$j("#checkout_button").click(function(e){
	
		e.preventDefault();
		$j(this).parents('form').attr('action', 'https://www.2checkout.com/2co/buyer/purchase');
		$j(this).parents('form').submit();
		
	});
	
	$j("#update_submit").click(function(e){
		e.preventDefault();
		$j(this).parents('form').trigger('submit');
	});
	
	$j(".delete_product a").click(function(e){
	
		e.preventDefault();
		
		$j(this).parents('.product').hide();
		$j(this).parents('.product').find('.quantity').val('0');
		docDirty = true;
		
		var items = $j('.product .quantity');
		var count = 0;
		$j(items).each(function(){
		
			if($j(this).val() > 0){
				count++;
			}
		
		});
		
		if(count == 0){
			$j("#empty_cart").slideDown('slow');
		}
		
	});
	
}

function initHomepage(){

	var images = $j("#homepage_scrollerabc img"); //homepage_scroller
	var width = 0;
	$j(images).each(function(){
		
		width += $j(this).width();
	
	});


	setTimeout("slideImagery()", 5000);

}

function slideImagery(){

	var width = $j("#homepage_scrollerabc img:eq(0)").width();
	
	$j("#homepage_scrollerabc img:eq(0)").animate({
	
		marginLeft: "-" + width + "px"
	
	}, 15000, 'linear', function(){
		var first = $j("#homepage_scrollerabc img:eq(0)").css('margin-left', '0px')
		$j("#homepage_scrollerabc a").append( $j(first) );
		slideImagery();
	});


}

function initCoverflow(){

	var instanceOne = new ImageFlow();
	instanceOne.init({ ImageFlowID:'myImageFlow' });
	
	$j(".scroll_left").click(function(e){
		e.preventDefault();
		instanceOne.handleMouseWheel(1);
	});
	
	$j(".scroll_right").click(function(e){
		e.preventDefault();
		instanceOne.handleMouseWheel(-1);
	});

}

function initGrids(){

	

	$j(".valign_me").each(function(){
	
		var gap = ( $j(this).parents('.description').height() - $j(this).height() )/ 4;
		$j(this).css('margin-top', gap + 'px');
	
	});
	
	$j(".scroll_right").click(function(e){
		e.preventDefault();
		scrollTo(selectedIndex + 1);
	});
	
	$j(".scroll_left").click(function(e){
		e.preventDefault();
		scrollTo(selectedIndex - 1);
	});
	
	$j('a.nolink').click(function(e){
	
		e.preventDefault();
	
	});
	
}

function scrollTo(index){
	var grids = $j('.grid');
	
	if(index < 0){
		//do nothing
	} else if(index >= grids.length){
		//do nothing
	} else {
		$j('ul').removeClass('onDisplay');
		$j('.scrollable').scrollTo('ul:eq(' + index + ')', 1000, {margin:true} );
		$j('.scrollable ul:eq(' + index + ')').addClass('onDisplay');
		selectedIndex = index;
	}

}

function view_more(doc_id){

	window.open(base_url + "index.php?id=70&target=" + doc_id, "view_more","menubar=0,resizable=1,scrollbars=1,width=1024,height=800"); 

}

function initNavigation(){
	
	$j("#nav-catalogue a").prepend("<span class='indicator_home'></span>");
	
	$j("#affiliates a").hover(function(){
		$j("~ .coming_soon", this).fadeIn();//css('display', 'block');
	}, function(){
		$j("~ .coming_soon", this).fadeOut();//css('display', 'none');
	});
	
	
	jQuery('#navigation_top').accordion({
			active: 'li.active a.primary',
			header: '.hasChildren a.primary',
			navigation: false,
			event: 'click',
			fillSpace: false,
			alwaysOpen: false,
			collapsible: true,
			autoheight: false,
			clearStyle: true
	});
	
	jQuery('ul.secondary').accordion({
			active: '.secondary li.active a',
			header: '.isF_Yes a.secondary',
			navigation: false,
			event: 'click',
			fillSpace: false,
			alwaysOpen: false,
			collapsible: true,
			autoheight: false,
			clearStyle: true
	});
	
	
	
}

;(function($) {
	
// If the UI scope is not available, add it
$.ui = $.ui || {};

$.fn.extend({
	accordion: function(options, data) {
		var args = Array.prototype.slice.call(arguments, 1);

		return this.each(function() {
			if (typeof options == "string") {
				var accordion = $.data(this, "ui-accordion");
				accordion[options].apply(accordion, args);
			// INIT with optional options
			} else if (!$(this).is(".ui-accordion"))
				$.data(this, "ui-accordion", new $.ui.accordion(this, options));
		});
	},
	// deprecated, use accordion("activate", index) instead
	activate: function(index) {
		return this.accordion("activate", index);
	}
});

$.ui.accordion = function(container, options) {
	
	// setup configuration
	this.options = options = $.extend({}, $.ui.accordion.defaults, options);
	this.element = container;
	
	$(container).addClass("ui-accordion");
	
	if ( options.navigation ) {
		var current = $(container).find("a").filter(options.navigationFilter);
		if ( current.length ) {
			if ( current.filter(options.header).length ) {
				options.active = current;
			} else {
				options.active = current.parent().parent().prev();
				current.addClass("current");
			}
		}
	}
	
	// calculate active if not specified, using the first header
	options.headers = $(container).find(options.header);
	options.active = findActive(options.headers, options.active);

	if ( options.fillSpace ) {
		var maxHeight = $(container).parent().height();
		options.headers.each(function() {
			maxHeight -= $(this).outerHeight();
		});
		var maxPadding = 0;
		options.headers.next().each(function() {
			maxPadding = Math.max(maxPadding, $(this).innerHeight() - $(this).height());
		}).height(maxHeight - maxPadding);
	} else if ( options.autoheight ) {
		var maxHeight = 0;
		options.headers.next().each(function() {
			maxHeight = Math.max(maxHeight, $(this).outerHeight());
		}).height(maxHeight);
	}

	options.headers
		.not(options.active || "")
		.next()
		.hide();
	options.active.parent().andSelf().addClass(options.selectedClass);
	
	if (options.event)
		$(container).bind((options.event) + ".ui-accordion", clickHandler);
};

$.ui.accordion.prototype = {
	activate: function(index) {
		// call clickHandler with custom event
		clickHandler.call(this.element, {
			target: findActive( this.options.headers, index )[0]
		});
	},
	
	enable: function() {
		this.options.disabled = false;
	},
	disable: function() {
		this.options.disabled = true;
	},
	destroy: function() {
		this.options.headers.next().css("display", "");
		if ( this.options.fillSpace || this.options.autoheight ) {
			this.options.headers.next().css("height", "");
		}
		$.removeData(this.element, "ui-accordion");
		$(this.element).removeClass("ui-accordion").unbind(".ui-accordion");
	}
}

function scopeCallback(callback, scope) {
	return function() {
		return callback.apply(scope, arguments);
	};
}

function completed(cancel) {
	// if removed while animated data can be empty
	if (!$.data(this, "ui-accordion"))
		return;
	var instance = $.data(this, "ui-accordion");
	var options = instance.options;
	options.running = cancel ? 0 : --options.running;
	if ( options.running )
		return;
	if ( options.clearStyle ) {
		options.toShow.add(options.toHide).css({
			height: "",
			overflow: ""
		});
	}
	$(this).triggerHandler("change.ui-accordion", [options.data], options.change);
}

function toggle(toShow, toHide, data, clickedActive, down) {
	var options = $.data(this, "ui-accordion").options;
	options.toShow = toShow;
	options.toHide = toHide;
	options.data = data;
	var complete = scopeCallback(completed, this);
	
	// count elements to animate
	options.running = toHide.size() == 0 ? toShow.size() : toHide.size();
	
	if ( options.animated ) {
		if ( !options.alwaysOpen && clickedActive ) {
			$.ui.accordion.animations[options.animated]({
				toShow: jQuery([]),
				toHide: toHide,
				complete: complete,
				down: down,
				autoheight: options.autoheight
			});
		} else {
			$.ui.accordion.animations[options.animated]({
				toShow: toShow,
				toHide: toHide,
				complete: complete,
				down: down,
				autoheight: options.autoheight
			});
		}
	} else {
		if ( !options.alwaysOpen && clickedActive ) {
			toShow.toggle();
		} else {
			toHide.hide();
			toShow.show();
		}
		complete(true);
	}
}

function clickHandler(event) {
	var options = $.data(this, "ui-accordion").options;
	if (options.disabled)
		return false;
	
	// called only when using activate(false) to close all parts programmatically
	if ( !event.target && !options.alwaysOpen ) {
		options.active.parent().andSelf().toggleClass(options.selectedClass);
		var toHide = options.active.next(),
			data = {
				instance: this,
				options: options,
				newHeader: jQuery([]),
				oldHeader: options.active,
				newContent: jQuery([]),
				oldContent: toHide
			},
			toShow = options.active = $([]);
		toggle.call(this, toShow, toHide, data );
		return false;
	}
	// get the click target
	var clicked = $(event.target);
	
	// due to the event delegation model, we have to check if one
	// of the parent elements is our actual header, and find that
	if ( clicked.parents(options.header).length )
		while ( !clicked.is(options.header) )
			clicked = clicked.parent();
	
	var clickedActive = clicked[0] == options.active[0];
	
	// if animations are still active, or the active header is the target, ignore click
	if (options.running || (options.alwaysOpen && clickedActive))
		return false;
	if (!clicked.is(options.header))
		return;

	// switch classes
	options.active.parent().andSelf().toggleClass(options.selectedClass);
	if ( !clickedActive ) {
		clicked.parent().andSelf().addClass(options.selectedClass);
	}

	// find elements to show and hide
	var toShow = clicked.next(),
		toHide = options.active.next(),
		//data = [clicked, options.active, toShow, toHide],
		data = {
			instance: this,
			options: options,
			newHeader: clicked,
			oldHeader: options.active,
			newContent: toShow,
			oldContent: toHide
		},
		down = options.headers.index( options.active[0] ) > options.headers.index( clicked[0] );
	
	options.active = clickedActive ? $([]) : clicked;
	toggle.call(this, toShow, toHide, data, clickedActive, down );

	return false;
};

function findActive(headers, selector) {
	return selector != undefined
		? typeof selector == "number"
			? headers.filter(":eq(" + selector + ")")
			: headers.not(headers.not(selector))
		: selector === false
			? $([])
			: headers.filter(":eq(0)");
}

$.extend($.ui.accordion, {
	defaults: {
		selectedClass: "selected",
		alwaysOpen: true,
		animated: 'slide',
		event: "click",
		header: "a",
		autoheight: true,
		running: 0,
		navigationFilter: function() {
			return this.href.toLowerCase() == location.href.toLowerCase();
		}
	},
	animations: {
		slide: function(options, additions) {
			options = $.extend({
				easing: "swing",
				duration: 300
			}, options, additions);
			if ( !options.toHide.size() ) {
				options.toShow.animate({height: "show"}, options);
				return;
			}
			var hideHeight = options.toHide.height(),
				showHeight = options.toShow.height(),
				difference = showHeight / hideHeight;
			options.toShow.css({ height: 0, overflow: 'hidden' }).show();
			options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate({height:"hide"},{
				step: function(now) {
					var current = (hideHeight - now) * difference;
					if ($.browser.msie || $.browser.opera) {
						current = Math.ceil(current);
					}
					options.toShow.height( current );
				},
				duration: options.duration,
				easing: options.easing,
				complete: function() {
					if ( !options.autoheight ) {
						options.toShow.css("height", "auto");
					}
					options.complete();
				}
			});
		},
		bounceslide: function(options) {
			this.slide(options, {
				easing: options.down ? "bounceout" : "swing",
				duration: options.down ? 1000 : 200
			});
		},
		easeslide: function(options) {
			this.slide(options, {
				easing: "easeinout",
				duration: 700
			})
		}
	}
});

})(jQuery);


/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 **/
 
;(function($){var m=$.scrollTo=function(b,h,f){$(window).scrollTo(b,h,f)};m.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1};m.window=function(b){return $(window).scrollable()};$.fn.scrollable=function(){return this.map(function(){var b=this,h=!b.nodeName||$.inArray(b.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!h)return b;var f=(b.contentWindow||b).document||b.ownerDocument||b;return $.browser.safari||f.compatMode=='BackCompat'?f.body:f.documentElement})};$.fn.scrollTo=function(l,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};if(l=='max')l=9e9;a=$.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=$(k),d=l,p,g={},q=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)){d=n(d);break}d=$(d,this);case'object':if(d.is||d.style)p=(d=$(d)).offset()}$.each(a.axis.split(''),function(b,h){var f=h=='x'?'Left':'Top',i=f.toLowerCase(),c='scroll'+f,r=k[c],s=h=='x'?'Width':'Height';if(p){g[c]=p[i]+(q?0:r-o.offset()[i]);if(a.margin){g[c]-=parseInt(d.css('margin'+f))||0;g[c]-=parseInt(d.css('border'+f+'Width'))||0}g[c]+=a.offset[i]||0;if(a.over[i])g[c]+=d[s.toLowerCase()]()*a.over[i]}else g[c]=d[i];if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],u(s));if(!b&&a.queue){if(r!=g[c])t(a.onAfterFirst);delete g[c]}});t(a.onAfter);function t(b){o.animate(g,j,a.easing,b&&function(){b.call(this,l,a)})};function u(b){var h='scroll'+b;if(!q)return k[h];var f='client'+b,i=k.ownerDocument.documentElement,c=k.ownerDocument.body;return Math.max(i[h],c[h])-Math.min(i[f],c[f])}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);


// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, 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;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, 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;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, 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;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, 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;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, 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;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (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;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (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;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (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 -.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 )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		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;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, 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 + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});
