/*
 * mbSlider v1.1.1 - for jQuery 1.3.2 +
 * http://codecanyon.net/item/mbslider/89466
 *
 * Copyright 2010, Michael Barrett
 * You need to buy a license if you want use this script.
 * http://codecanyon.net/wiki/buying/howto-buying/licensing/
 *
 * Date: 13/3/2010
 *
 * For API documentation, FAQ's, Examples and other useful information visit http://www.mb-tools.co.uk/mbslider
 *
 */

(function($){

	$.fn.mbSlider = function(usersettings){
		
		//defaults
		var defaults = {
			autoplay: false,
			showControls: { 
				next: true, 
				prev: true, 
				play: true, 
				pause: true, 
				first: true, 
				last: true 
			},
			playPauseButtonSeperate: false,
			controlsText: {
				next: "Next",
				prev: "Previous",
				play: "Play",
				pause: "Pause",
				first: "First",
				last: "Last"
			},
			controlsLocation: "external",
			slideDuration: 5000,
			slideSpeed: 800,
			backToStart: true,
			backToStartSpeed: 200,
			backToEnd: true,
			backToEndSpeed: 200,
			startSlide: 1,
			pagination: true,
			paginationLocation: "external",
			pauseOnHover: true,
			orientation: "horizontal",
			playDirection: "right",
			continuous: false,
			easing: "swing",
			mousewheelsupport: true,
			callbacks : {
				movenext: false,
				moveprev: false,
				movefirst: false,
				movelast: false,
				play: false,
				pause: false,
				movestart: false,
				moveend: false,
				mousewheelup: false,
				mousewheeldown: false,
				hoveron: false,
				hoverout: false,
				controlsclick: false,
				controlshoveron: false,
				controlshoverout: false,
				paginationclick: false,
				paginationhoveron: false,
				paginationhoverout: false
			}
		};
 
		//load settings (taking into account user defined settings)
		var settings = $.extend(true, defaults, usersettings);
		
		//core
		return this.each(function(){
			
			$(this).addClass("mbSlider"); //do this first to calculate how many sliders there are going to be.
			$(this).find("ul:first").addClass("mbSlider_Slides"); //do this so user can use UL and LI inside Slider
			$(this).find("ul:first > li").addClass("mbSlider_Slide");
			
			//variables
			var numOfSlides = $(this).find("li.mbSlider_Slide").length;
			var slideWidth = $(this).find("li.mbSlider_Slide").width();
			var slideHeight = $(this).find("li.mbSlider_Slide").height();
			var clickable = true;
			var currentSlide = settings.startSlide;
			var status;
			var timer;
			var pausedByHover;
			var obj = this; //for use inside functions
			var sId = $(this).attr("id"); //slider id
			
			//functions
			function movenext(){
				if(settings.callbacks.movenext){ settings.callbacks.movenext(); }
				if(currentSlide == numOfSlides){
					if(settings.callbacks.movestart){ settings.callbacks.movestart(); }
					if(settings.backToStart){
						if(settings.continuous){
							if(clickable){
								clickable = false;
								if(settings.orientation=="horizontal"){
									$(obj).find("ul.mbSlider_Slides").css("width", (numOfSlides*slideWidth)+slideWidth+"px");
									$(obj).find("li.mbSlider_Slide:first").clone().appendTo( $(obj).find("ul.mbSlider_Slides") );
									$(obj).find("ul.mbSlider_Slides").animate({ marginLeft: 0 - (( (numOfSlides+1) * slideWidth) - slideWidth) },
									{
										duration: settings.slideSpeed,
										easing: settings.easing,
										complete: function(){
											$(obj).find("ul.mbSlider_Slides").css("margin-left","0px");
											$(obj).find("li.mbSlider_Slide:last").remove();
											$(obj).find("ul.mbSlider_Slides").css("width", numOfSlides*slideWidth);
											clickable = true;
											currentSlide = 1;
											paginationCurrentSlide();
											if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
										}
									});
								}
								if(settings.orientation=="vertical"){
									$(obj).find("ul.mbSlider_Slides").css("height", (numOfSlides*slideHeight)+slideHeight+"px");
									$(obj).find("li.mbSlider_Slide:first").clone().appendTo( $(obj).find("ul.mbSlider_Slides") );
									$(obj).find("ul.mbSlider_Slides").animate({ marginTop: 0 - (( (numOfSlides+1) * slideHeight) - slideHeight) },
									{
										duration: settings.slideSpeed,
										easing: settings.easing,
										complete: function(){
											$(obj).find("ul.mbSlider_Slides").css("margin-top","0px");
											$(obj).find("li.mbSlider_Slide:last").remove();
											$(obj).find("ul.mbSlider_Slides").css("height", numOfSlides*slideHeight);
											clickable = true;
											currentSlide = 1;
											paginationCurrentSlide();
											if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
										}
									});
								}
							}
						}
						else{
							goto(1);
						}
					}
				}
				else {
					animate(1);
				}
			}
			
			function moveprev(){
				if(settings.callbacks.moveprev){ settings.callbacks.moveprev(); }
				if(currentSlide == 1){
					if(settings.callbacks.movestart){ settings.callbacks.movestart(); }
					if(settings.backToEnd){
						if(settings.continuous){
							if(clickable){
								clickable = false;
								if(settings.orientation=="horizontal"){
									$(obj).find("ul.mbSlider_Slides").css("width", (numOfSlides*slideWidth)+slideWidth+"px");
									$(obj).find("li.mbSlider_Slide:last").clone().prependTo( $(obj).find("ul.mbSlider_Slides") );
									$(obj).find("ul.mbSlider_Slides").css("margin-left","-"+slideWidth+"px" );
									$(obj).find("ul.mbSlider_Slides").animate({ marginLeft: 0 },
									{
										duration: settings.slideSpeed,
										easing: settings.easing,
										complete: function(){
											$(obj).find("li.mbSlider_Slide:first").remove();
											$(obj).find("ul.mbSlider_Slides").css("margin-left",0 - ((numOfSlides*slideWidth)-slideWidth) );
											clickable = true;
											currentSlide = numOfSlides;
											paginationCurrentSlide();
											if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
										}
									});
								}
								if(settings.orientation=="vertical"){
									$(obj).find("ul.mbSlider_Slides").css("height", (numOfSlides*slideHeight)+slideHeight+"px");
									$(obj).find("li.mbSlider_Slide:last").clone().prependTo( $(obj).find("ul.mbSlider_Slides") );
									$(obj).find("ul.mbSlider_Slides").css("margin-top","-"+slideHeight+"px" );
									$(obj).find("ul.mbSlider_Slides").animate({  marginTop: 0 },
									{
										duration: settings.slideSpeed,
										easing: settings.easing,
										complete: function(){
											$(obj).find("li.mbSlider_Slide:first").remove();
											$(obj).find("ul.mbSlider_Slides").css("margin-top",0 - ((numOfSlides*slideHeight)-slideHeight) );
											clickable = true;
											currentSlide = numOfSlides;
											paginationCurrentSlide();
											if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
										}
									});
								}
							}
						}
						else{
							goto(numOfSlides);
						}
					}
				}
				else {
					animate(-1);
				}
			}
			
			
			function pause(){
					if(settings.callbacks.pause){ settings.callbacks.pause(); }
					status = 0;
					clearTimeout(timer);
			}
			
			function play(){
				if(settings.callbacks.play){ settings.callbacks.play(); }
				status = 1;
				switch(settings.playDirection){
					case "right":
						movenext();
					break;
					case "left":
						moveprev();
					break;
					case "up":
						movenext();
					break;
					case "down":
						moveprev();

					break;
				}
				clearTimeout(timer);
				timer = setTimeout( function(){ play(); }, settings.slideDuration );
			}
			
			function goto(slide){
				if(settings.callbacks.movestart){ settings.callbacks.movestart(); }
				if(slide == 1 && settings.callbacks.movefirst){ settings.callbacks.movefirst(); }
				if(slide == numOfSlides && settings.callbacks.movelast){ settings.callbacks.movelast(); }
				if(clickable){
					clickable = false;
					if(settings.orientation=="horizontal"){
						$(obj).find("ul.mbSlider_Slides").animate({ 
							marginLeft: 0 - ((slide * slideWidth) - slideWidth) },
							{
								duration: settings.slideSpeed,
								easing: settings.easing,
								complete: function(){
									clickable = true;
									currentSlide = slide;
									paginationCurrentSlide();
									if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
								}
							});
					}
					if(settings.orientation=="vertical"){
							$(obj).find("ul.mbSlider_Slides").animate({ marginTop: 0 - ((slide * slideHeight) - slideHeight) },
							{
								duration: settings.slideSpeed,
								easing: settings.easing,
								complete: function(){
									clickable = true;
									currentSlide = slide;
									paginationCurrentSlide();
									if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
								}
							});
					}
				}
			}


			function animate(direction){
				if(settings.callbacks.movestart){ settings.callbacks.movestart(); }
				if(clickable){
					clickable = false;
					if(settings.orientation=="horizontal"){
						if(direction==1){
							$(obj).find("ul.mbSlider_Slides").animate({ marginLeft: 0 - (currentSlide * slideWidth) },
							{
								duration: settings.slideSpeed,
								easing: settings.easing,
								complete: function(){
									clickable = true;
									currentSlide++;
									paginationCurrentSlide();
									if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
								}
							});
						}
						if(direction==-1){
							currentSlide--;
							$(obj).find("ul.mbSlider_Slides").animate({ marginLeft: 0 - ((currentSlide * slideWidth) - slideWidth) },
							{
								duration: settings.slideSpeed,
								easing: settings.easing,
								complete: function(){
									clickable = true;
									paginationCurrentSlide();
									if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
								}
							});
						}
					}
					if(settings.orientation=="vertical"){
						if(direction==1){
							$(obj).find("ul.mbSlider_Slides").animate({ marginTop: 0 - (currentSlide * slideHeight) },
							{
								duration: settings.slideSpeed,
								easing: settings.easing,
								complete: function(){
									clickable = true;
									currentSlide++;
									paginationCurrentSlide();
									if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
								}
							});
						}
						if(direction==-1){
							currentSlide--;
							$(obj).find("ul.mbSlider_Slides").animate({ marginTop: 0 - ((currentSlide * slideHeight) - slideHeight) },
							{
								duration: settings.slideSpeed,
								easing: settings.easing,
								complete: function(){
									clickable = true;
									paginationCurrentSlide();
									if(settings.callbacks.moveend){ settings.callbacks.moveend(); }
								}
							});
						}
					}
				}
			}
			
			function paginationCurrentSlide(){
				if(settings.pagination){
					$("._current-slide").removeClass("_current-slide");
					$("#"+sId+"_pagination").find("a").eq(currentSlide-1).addClass("_current-slide");
				}
				$("._active-slide").removeClass("_active-slide");
				$(".mbSlider_Slide").eq(currentSlide-1).addClass("_active-slide");
			}
			
			//INIT
			//init controls structure
			if(settings.showControls){
				var controlsStructure = "<div id='"+sId+"_controls'>";
				if(settings.showControls.next){
					controlsStructure += "<a href='javascript:void(0);' class='button arrow right' id='"+sId+"_movenext'><span class='icon'>&nbsp;</span>"+settings.controlsText.next+"</a>";	
				}
				if(settings.showControls.prev){
					controlsStructure += "<a href='javascript:void(0);' class='button arrow left' id='"+sId+"_moveprev'><span class='icon'>&nbsp;</span>"+settings.controlsText.prev+"</a>";	
				}
				if(settings.showControls.play){
					controlsStructure += "<a href='javascript:void(0);' id='"+sId+"_play'>"+settings.controlsText.play+"</a>";
				}
				if(settings.showControls.pause){
					controlsStructure += "<a href='javascript:void(0);' id='"+sId+"_pause'>"+settings.controlsText.pause+"</a>";	
				}
				if(settings.showControls.first){
					controlsStructure += "<a href='javascript:void(0);' id='"+sId+"_movefirst'>"+settings.controlsText.first+"</a>";
				}
				if(settings.showControls.last){
					controlsStructure += "<a href='javascript:void(0);' id='"+sId+"_movelast'>"+settings.controlsText.last+"</a>";	
				}
				controlsStructure += "</div>";
				
				if(settings.controlsLocation=="external"){
					$(this).before(controlsStructure);
				}
				if(settings.controlsLocation=="internal"){
					$(this).append(controlsStructure);
				}
				
				$("#"+sId+"_controls a").click(function(){ 
					pause();
					if(settings.callbacks.controlsclick){ 
						settings.callbacks.controlsclick(); 
					} 
				});
				$("#"+sId+"_controls").hover(function(){
					if(settings.callbacks.controlshoveron){ settings.callbacks.controlshoveron(); } 
				},function(){
					if(settings.callbacks.controlshoverout){ settings.callbacks.controlshoverout(); } 		
				});
				
				
				$("#"+sId+"_movenext").click(function(){ movenext(); });
				$("#"+sId+"_moveprev").click(function(){ moveprev(); });
				$("#"+sId+"_play").click(function(){
					if(status != 1){
						play();
					}
				});
				$("#"+sId+"_pause").click(function(){
					if(status !== 0){
						pause();
					}				
				});
				$("#"+sId+"_movefirst").click(function(){ goto(1); });
				$("#"+sId+"_movelast").click(function(){ goto(numOfSlides); });
				
				if(!settings.playPauseButtonSeperate){
					$("#"+sId+"_play,#"+sId+"_pause").wrapAll("<div id='temp'></div>");
					$("#temp").replaceWith("<a id='"+sId+"_playpause' href='javascript:void(0);'></a>");
				
					$("#"+sId+"_playpause").click(function(){ 
						if( status == 1 ){
							clearTimeout(timer);
							pause();
							$(this).html(settings.controlsText.play).removeClass("playing").addClass("paused");
						}
						else {
							status = 1;
							clearTimeout(timer);
							timer = setTimeout( function(){ play(); }, settings.slideDuration );
							$(this).html(settings.controlsText.pause).removeClass("paused").addClass("playing");
						}
					});
				}
			}
			
			//init user defineable control classes
			$("."+sId+"_movenext").click(function(){ movenext(); });
			$("."+sId+"_moveprev").click(function(){ moveprev(); });
			$("."+sId+"_play").click(function(){ 
				if(status != 1){
					play();
				}
			});
			$("."+sId+"_pause").click(function(){ 
				if(status !== 0){
					pause();
				}
			});
			$("."+sId+"_movefirst").click(function(){ goto(1); });
			$("."+sId+"_movelast").click(function(){ goto(numOfSlides); });
			$("[class*='"+sId+"_goto']").click(function(){
				var gotoslide;
				var classes = $(this).attr("class").split(" ");
				for(var i=0; i<=classes.length-1; i++){
					if(classes[i].search(sId+"_gotoSlide")>=0){
						gotoslide = classes[i].substring(classes[i].indexOf("[")+1,classes[i].indexOf("]"));
					}
				}
				goto(gotoslide);
			});

			
			//init pagination
			if(settings.pagination){
				paginationStructure = "<div id='"+sId+"_pagination'>";
				for(var i=1; i<=numOfSlides; i++){
					if(i==settings.startSlide){
						paginationStructure += "<a href='javascript:void(0);' class='_current-slide'>"+i+"</a>";
					}
					else {
						paginationStructure += "<a href='javascript:void(0);'>"+i+"</a>";
					}
				}
				paginationStructure += "</div>";
				
				if(settings.paginationLocation=="external"){
					$(this).after(paginationStructure);
				}
				if(settings.paginationLocation=="internal"){
					$(this).append(paginationStructure);
				}

				$("#"+sId+"_pagination a").click(function(){ goto( $(this).html() ); });
			
				$("#"+sId+"_pagination a").click(function(){ if(settings.callbacks.paginationclick){ settings.callbacks.paginationclick(); } });
				$("#"+sId+"_pagination").hover(function(){
					if(settings.callbacks.paginationhoveron){ settings.callbacks.paginationhoveron(); } 
				},function(){
					if(settings.callbacks.paginationhoverout){ settings.callbacks.paginationhoverout(); } 		
				});
				
			}
			
			//init autoplay
			if(settings.autoplay){
				timer = setTimeout( function(){ play(); }, settings.slideDuration );
				status = 1;
			}
			else {
				status = 0;
			}
			
			//init play/pause button (if not using seperate play / pause buttons
			if(status==1){
				$("#"+sId+"_playpause").html(settings.controlsText.pause).addClass("playing");
			}
			else {
				$("#"+sId+"_playpause").html(settings.controlsText.play).addClass("paused");
			}
			
			//init onhover pause (if enabled)
			if(settings.pauseOnHover){
					$(this).find("li.mbSlider_Slide").hover(function(){
						if(status==1){
							pause();
							pausedByHover = 1;
						}
					},function(){
						if(pausedByHover==1){
							timer = setTimeout( function(){ play(); }, settings.slideDuration );
							pausedByHover = 0;
						}
					});
			}
			
			//set up styling
			//css for slider ul
			$(this).find("ul.mbSlider_Slides").css({
				"list-style":"none",
				"margin-left":"0px",
				"padding-left":"0px"
			});
			
			if(settings.orientation=="vertical"){
				$(this).find("ul.mbSlider_Slides").css("height", numOfSlides * slideHeight + "px");
				//init slide to start on
				$(this).find("ul.mbSlider_Slides").css("margin-top",0 - ((currentSlide * slideHeight) - slideHeight));
			}
			
			if(settings.orientation=="horizontal"){
				$(this).find("ul.mbSlider_Slides").css("width", numOfSlides * slideWidth + "px");
				//init slide to start on
				$(this).find("ul.mbSlider_Slides").css("margin-left",0 - ((currentSlide * slideWidth) - slideWidth));
			}
			
			$(".mbSlider_Slide").eq(currentSlide-1).addClass("_active-slide");
			
			//css for slider container
			$(this).css({
				"overflow":"hidden",
				"height": slideHeight + "px",
				"width": slideWidth + "px",
				"position": "relative"
			});
			
			//css for slides (li)
			$(this).find("li.mbSlider_Slide").css("float","left");
			
			//mousewheel support
			if(settings.mousewheelsupport == true){
				$(this).mousewheel(function(event, delta) {
					if(delta > 0){ movenext(); if(settings.callbacks.mousewheelup){ settings.callbacks.mousewheelup(); } return false; }
					if(delta < 0){ moveprev(); if(settings.callbacks.mousewheeldown){ settings.callbacks.mousewheeldown(); } return false; }
				});
			}
			
			//hover on/out callback
			$(this).find("li.mbSlider_Slide").hover(function(){
				if(settings.callbacks.hoveron){ settings.callbacks.hoveron(); } 
			},function(){
				if(settings.callbacks.hoverout){ settings.callbacks.hoverout(); } 		
			});
		});
	};
})(jQuery);


/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// 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;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */


/*! Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * Version: 3.0.2
 * 
 * Requires: 1.2.2+
 */

(function($) {

var types = ['DOMMouseScroll', 'mousewheel'];

$.event.special.mousewheel = {
	setup: function() {
		if ( this.addEventListener )
			for ( var i=types.length; i; )
				this.addEventListener( types[--i], handler, false );
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		if ( this.removeEventListener )
			for ( var i=types.length; i; )
				this.removeEventListener( types[--i], handler, false );
		else
			this.onmousewheel = null;
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});


function handler(event) {
	var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
	
	event = $.event.fix(event || window.event);
	event.type = "mousewheel";
	
	if ( event.wheelDelta ) delta = event.wheelDelta/120;
	if ( event.detail     ) delta = -event.detail/3;
	
	// Add events and delta to the front of the arguments
	args.unshift(event, delta);

	return $.event.handle.apply(this, args);
}

})(jQuery);
