/*
 *
 * mbSlider v1.2 - for jQuery 1.3.2+
 * http://codecanyon.net/item/mbslider/89466
 *
 * Copyright 2010, Michael David Barrett
 * http://codecanyon.net/user/mike182uk
 *
 * You need to buy a license to use this script.
 * http://codecanyon.net/wiki/buying/howto-buying/licensing/
 *
 * Date: 25/8/2010
 *
 * For API documentation, FAQ's, Examples and other useful information visit http://www.mb-tools.co.uk/mbslider
 *
 */
(function($){
	
	//used to fix method calling issues on un-instantiated objects
	$.bind = function(object,method){
		var args = Array.prototype.slice.call(arguments,2);
		return function(){
			var args2 = [this].concat(args,$.makeArray(arguments));
			return method.apply(object,args2);
		};
	};
	
	//mbSlider object
	var mbSlider = function(){};
	
	//extend mbSlider object prototype
	mbSlider.prototype = {
		init:function(e,config)
		{
			var self = this,
				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: 'horizontal',
					slideDuration: 19000,
					slideSpeed: 800,
					backToStart: false,
					backToStartSpeed: 300,
					backToEnd: false,
					backToEndSpeed: 300,
					startSlide: 1,
					pagination: true,
					paginationLocation: 'external',
					pauseOnHover: true,
					orientation: 'horizontal',
					playDirection: 'ltr',
					continuous: true,
					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
					},
					fadeControlsHover:false,
					fadeControlsHoverSpeed: 200,
					fadePaginationHover: false,
					fadePaginationHoverSpeed: 200,
					randomizeOnInit:false,
					slideDurations: {}
				};
			
			this.settings = $.extend(true,defaults,config);
			this.obj = e;
			this.e = $(e);
			this.id = this.obj.id;
			this.slides = this.e.find('ul:first');
			this.slides.find('li')
					   .addClass('mbSlider_slide')
					   .css({
							'float':'left'
						});
			this.numOfSlides = this.e.find('li').length;
			this.slideHeight = this.e.find('li').eq(0).height();
			this.slideWidth = this.e.find('li').eq(0).width();
			this.currentSlide = this.settings.startSlide;
			this.pausedByHover = 0;
			if(this.settings.orientation == 'horizontal'){
				var marginLeft = '-'+((this.currentSlide - 1) * this.slideWidth)+'px',
					marginTop = '0px',
					width = (this.numOfSlides * this.slideWidth),
					height = this.slideHeight;
			}
			else {
				var marginLeft = '0px',
					marginTop = '-'+((this.currentSlide - 1) * this.slideHeight)+'px',
					width = this.slideWidth,
					height = (this.numOfSlides * this.slideHieght);
			}
			this.slides.css({
							'list-style':'none',
							'margin-left': marginLeft,
							'margin-top': marginTop,
							'padding-left':'0px',
							'padding-top':'0px',
							'width': width,
							'height': height
						})
						.addClass('mbSlider_slides');
			this.e.css({
				'width':this.slideWidth,
				'height':this.slideHeight,
				'overflow':'hidden'
			});
			this.clickStatus = 1;
			this.hoverStatus = 1;
			this.playStatus = (this.settings.autoplay) ? 1 : 0;
			this.timer = 0;
			this.e.css({
				'overflow':'hidden',
				'height':this.slideHeight + 'px',
				'width':this.slideWidth + 'px',
				'position':'relative'
			});
			
			//init class for first slide
			this.e.find('li').eq(this.currentSlide - 1).addClass('mbSlider_active_slide');
			
			//inject controls
			if(this.settings.showControls){ this.inject( this.settings.controlsLocation, this.generateControls() ); }
			
			//inject pagination
			if(this.settings.pagination){ this.inject( this.settings.paginationLocation, this.generatePagination() ); }
			
			//cache DOM elements for pagination and controls into object
			this.pagination = $('#'+this.id+'_pagination').get(0);
			this.controls = $('#'+this.id+'_pagination').get(0);
			
			//init randomize slides
			if(this.settings.randomizeOnInit){ this.randomizeSlides(); }
			
			//attach event bindings
			this.eventBindings();
			
			//init autoplay
			if(this.settings.autoplay){
				this.play(1);
			}
			else {
				this.e.addClass('mbSlider_paused');	
			}
		},
		getSlideDuration:function()
		{
			return (this.settings.slideDurations['slide_' + this.currentSlide] !== undefined) ? this.settings.slideDurations['slide_' + this.currentSlide] : this.settings.slideDuration;
		},
		movenext:function()
		{
			var slide,animSpeed,backtostart;
			if(this.currentSlide + 1 == this.numOfSlides + 1){
				slide = 1;
				backtostart = 1;
				animSpeed = this.settings.backToStartSpeed;
				if(!this.settings.backToStart && !this.settings.continuous){ return false; }
			}
			else {
				slide = this.currentSlide + 1;
			}
			this.goto(slide,animSpeed,backtostart);
			if(this.settings.callbacks.moveprev !== false){ this.settings.callbacks.moveprev(this); }
		},
		moveprev:function()
		{
			var slide,animSpeed,backtoend;
			if(this.currentSlide - 1 == 0){
				slide =  this.numOfSlides;
				backtoend = 2;
				animSpeed = this.settings.backToEndSpeed;
				if(!this.settings.backToEnd && !this.settings.continuous){ return false; }
			}
			else {
				slide = this.currentSlide - 1;
			}
			this.goto(slide,animSpeed,backtoend);
			if(this.settings.callbacks.movenext !== false){ this.settings.callbacks.movenext(this); }
		},
		play:function(prepOnly)
		{
			var self = this;
			this.playStatus = 1;
			if(prepOnly !== 1){
				this.e.addClass('mbSlider_playing')
					  .removeClass('mbSlider_paused');
				if(!this.settings.playPauseButtonSeperate){
					$('#'+this.id+'_playpause').text(this.settings.controlsText.pause);
				}
				switch(this.settings.playDirection){
					case 'ltr': case 'btt':
						this.movenext();
					break;
					case 'rtl': case 'ttb':
						this.moveprev();
					break;
				}
				clearInterval(this.timer);
			}
			this.e.addClass('mbSlider_playing')
				  .removeClass('mbSlider_paused');
			if(!this.settings.playPauseButtonSeperate){
				$('#'+this.id+'_playpause').text(this.settings.controlsText.pause);
			}
			this.timer = setInterval(function(){ $.bind(self,self.play()); }, self.getSlideDuration() );
			if(this.settings.callbacks.play !== false){ this.settings.callbacks.play(this); }
		},
		pause:function()
		{
			if(this.playStatus == 1){
				clearInterval(this.timer);
				this.playStatus = 0;
				this.e.addClass('mbSlider_paused')
					  .removeClass('mbSlider_playing');
				if(!this.settings.playPauseButtonSeperate && !this.pausedByHover){
					$('#'+this.id+'_playpause').text(this.settings.controlsText.play);	
				}
				if(this.settings.callbacks.pause !== false){ this.settings.callbacks.pause(this); }
			}
		},
		movefirst:function()
		{
			this.goto(1);
			if(this.settings.callbacks.movefirst !== false){ this.settings.callbacks.movefirst(this); }
		},
		movelast:function()
		{
			this.goto(this.numOfSlides);
			if(this.settings.callbacks.movelast !== false){ this.settings.callbacks.movelast(this); }
		},
		goto:function(slide,animSpeed,startEnd)
		{	
			if(this.clickStatus == 1){
				var dir,
					val,
					measure = (this.settings.orientation == 'horizontal') ? this.slideWidth : this.slideHeight;
				
				this.clickStatus = 0;
				if(this.currentSlide == slide){
					this.clickStatus = 1;
					return false;
				}
				else {
					if(slide < this.currentSlide){
						val = (this.currentSlide - slide) * measure;
						dir = -1;
					}
					else {
						val = (slide - this.currentSlide) * measure;
						dir = 1;
					}
					this.currentSlide = slide;
				}
				if(this.settings.pagination){
					$('.mbSlider_current_slide').removeClass('mbSlider_current_slide');
					$('#'+this.id+'_pagination').find('a')
												.eq(this.currentSlide - 1)
												.addClass('mbSlider_current_slide');
				}
				this.animate(dir,val,animSpeed,startEnd);
			}
		},
		animate:function(direction,value,animationSpeed,startEnd)
		{
			if(this.settings.callbacks.movestart !== false){ this.settings.callbacks.movestart(this); }
			
			var dir = (direction == 1) ? '-=' : '+=',
				val = value,
				self = this,
				slideOrientation = this.settings.orientation,
				animationCSS;
			
			if(this.settings.continuous){
				animationSpeed = false;
				if(startEnd == 1){
					if(slideOrientation == 'horizontal'){
						this.slides.css({
							'width':((this.numOfSlides + 1 ) * this.slideWidth) + 'px'
						});
					}
					else {
						this.slides.css({
							'height':((this.numOfSlides + 1 ) * this.slideHeight) + 'px'
						});	
					}
					this.slides.append( this.slides.find('li:first').clone() );
					dir = '-=';
					val = (slideOrientation == 'horizontal') ? this.slideWidth : this.slideHeight;	
				}
				if(startEnd == 2){
					if(slideOrientation == 'horizontal'){
						this.slides.css({
							'width':((this.numOfSlides + 1 ) * this.slideWidth) + 'px',
							'margin-left':'-'+this.slideWidth + 'px'
						});
					}
					else {
						this.slides.css({
							'height':((this.numOfSlides + 1 ) * this.slideHeight) + 'px',
							'margin-top':'-'+this.slideHeight + 'px'
						});
					}
					this.slides.prepend( this.slides.find('li:last').clone() );
					dir = '+=';
					val = (slideOrientation == 'horizontal') ? this.slideWidth : this.slideHeight;
				}
			}
			
			if(slideOrientation == 'horizontal'){
				animationCSS = {
					marginLeft : dir + val
				};
			}
			else {
				animationCSS = {
					marginTop : dir + val
				};
			}
			
			this.slides.animate(animationCSS,{
				duration: ((animationSpeed) ? animationSpeed : this.settings.slideSpeed),
				easing: this.settings.easing,
				complete: function(){
					if(startEnd && self.settings.continuous){
						self.resetSlider(startEnd);
					}
					self.slides.find('.mbSlider_active_slide').removeClass('mbSlider_active_slide');
					self.slides.find('li').eq(self.currentSlide - 1)
										  .addClass('mbSlider_active_slide');
					
					self.clickStatus = 1;
					if(self.settings.callbacks.moveend !== false){ self.settings.callbacks.moveend(self); }
				}
			});
		},
		resetSlider:function(startEnd)
		{
			var originalWidth = (this.numOfSlides * this.slideWidth) + 'px',
				originalHeight = (this.numOfSlides * this.slideHeight) + 'px';
			
			this.slides.find('li:last').remove();
			
			if(startEnd == 1){
				this.currentSlide = 1;
				if(this.settings.orientation == 'horizontal'){
					this.slides.css({
						'margin-left':'0px',
						'width':originalWidth  
					});
				}
				else {
					this.slides.css({
						'margin-top':'0px',
						'height':originalHeight  
					});
				}
			}
			if(startEnd == 2){
				this.currentSlide = this.numOfSlides;
				if(this.settings.orientation == 'horizontal'){
					this.slides.css({
						'margin-left':'-' + ((this.numOfSlides - 1) * this.slideWidth) + 'px',
						'width':originalWidth 
					});
				}
				else {
					this.slides.css({
						'margin-top':'-' + ((this.numOfSlides - 1) * this.slideHeight) + 'px',
						'height':originalHeight 
					});
				}
			}
		},
		inject:function(location,html)
		{
			if(location == 'internal'){
				this.e.append(html);
			}
			else {
				this.e.after(html);
			}
		},
		generateControls:function()
		{
			var controls = {
				next: {
					id: '_movenext',
					href: 'javascript:void(0)',
					label: this.settings.controlsText.next,
					show: this.settings.showControls.next
				},
				prev: {
					id: '_moveprev',
					href: 'javascript:void(0)',
					label: this.settings.controlsText.prev,
					show: this.settings.showControls.prev
				},
				play: {
					id: '_play',
					href: 'javascript:void(0)',
					label: this.settings.controlsText.play,
					show: this.settings.showControls.play
				},
				pause: {
					id: '_pause',
					href: 'javascript:void(0)',
					label: this.settings.controlsText.pause,
					show: this.settings.showControls.pause
				},
				first: {
					id: '_movefirst',
					href: 'javascript:void(0)',
					label: this.settings.controlsText.first,
					show: this.settings.showControls.first
				},
				last: {
					id: '_movelast',
					href: 'javascript:void(0)',
					label: this.settings.controlsText.last,
					show: this.settings.showControls.last
				}
			};
			
			var controlsStructure = '<div id="'+this.id+'_controls">';
			for(x in controls){
				var c = controls[x];
				if(c.show){
					controlsStructure += '<a href="'+c.href+'" id="'+this.id + c.id+'">'+c.label+'</a>';
				}
			}
			controlsStructure += "</div>";
			
			if(!this.settings.playPauseButtonSeperate){
				var playPauseLabel = (this.settings.autoplay) ? 'Pause' : 'Play';
				controlsStructure = $(controlsStructure);
				controlsStructure.find("a[id='"+this.id+"_pause']")
								 .after('<a id="'+this.id+'_playpause" href="javascript:void(0);">'+playPauseLabel+'</a>');
				controlsStructure.find("a[id='"+this.id+"_pause'], a[id='"+this.id+"_play']")
								 .remove();
			}		
			if(this.settings.fadeControlsHover){
				controlsStructure.hide();
			}
			return controlsStructure;
		},
		generatePagination:function()
		{
			var paginationStructure = '<div id="'+this.id+'_pagination">';
			for(var i=1; i<=this.numOfSlides; i++){
				var klass = (i==this.settings.startSlide) ? 'mbSlider_current_slide' : '';
				paginationStructure += '<a href="javascript:void(0);" class="'+klass+'">'+i+'</a>';
			}
			paginationStructure += "</div>";
			if(this.settings.fadePaginationHover){
				paginationStructure = $(paginationStructure);
				paginationStructure.hide();
			}
			return paginationStructure;
		},
		randomizeSlides:function(){
			var slides = [];
			this.slides.find('li').each(function(){
				slides.push($(this));
				$(this).remove();
			});
			slides.sort(function(){ return Math.round(Math.random())-0.5; });
			for(x in slides){
				this.slides.append(slides[x]);	
			}
		},
		eventBindings:function()
		{
			var self = this;
					
			//controls / pagination
			$('#'+this.id+'_movenext, .'+this.id+'_movenext').bind('click',function(){ self.movenext(); });
			$('#'+this.id+'_moveprev, .'+this.id+'_moveprev').bind('click',function(){ self.moveprev(); });
			$('#'+this.id+'_movefirst, .'+this.id+'_movefirst').bind('click',function(){ self.movefirst(); });
			$('#'+this.id+'_movelast, .'+this.id+'_movelast').bind('click',function(){ self.movelast(); });
			$('#'+this.id+'_play, .'+this.id+'_play').bind('click',function(){ self.play(1); });
			$('#'+this.id+'_pause, .'+this.id+'_pause').bind('click',function(){ self.pause(); });
			$('#'+this.id+'_playpause').bind('click',function(){ 
				if(self.playStatus == 0){
					self.play(1);
				}
				else {
					self.pause();
				}
			});
			$('#'+this.id+'_pagination').find('a').bind('click',function(){
				self.goto(parseInt($(this).text()));
			});
			
			//controls callbacks
			$('#'+this.id+'_controls').bind('mouseover',function(){ 
									      if(self.settings.callbacks.controlshoveron !== false){ self.settings.callbacks.controlshoveron(self); } 
									  })
									  .bind('mouseout',function(){ 
									      if(self.settings.callbacks.controlshoverout !== false){ self.settings.callbacks.controlshoverout(self); }
									  })
									  .find('a')
									  .bind('click',function(){ 
									      if(self.settings.callbacks.controlsclick !== false){ self.settings.callbacks.controlsclick(self); }
									  });
			
			//pagination callbacks
			$('#'+this.id+'_pagination').bind('mouseover',function(){ 
											  if(self.settings.callbacks.paginationhoveron !== false){ self.settings.callbacks.paginationhoveron(self); }
										  })
										  .bind('mouseout',function(){ 
											  if(self.settings.callbacks.paginationhoverout !== false){ self.settings.callbacks.paginationhoverout(self);}
										  })
										  .find('a')
										  .bind('click',function(){ 
											  if(self.settings.callbacks.paginationclick !== false){ self.settings.callbacks.paginationclick(self); }
										  });
			
			//slider hover statuses
			this.e.bind('mouseover',function(){
							if(self.settings.callbacks.hoveron !== false){ self.settings.callbacks.hoveron(self); }
						}).bind('mouseout',function(){
							if(self.settings.callbacks.hoverout !== false){ self.settings.callbacks.hoverout(self); }
						});
				
			
			//user defined pagination
			$("[class*='"+self.id+"_gotoSlide']").bind('click',function(){
				var slide;
				var classes = $(this).attr('class').split(' ');
				for(c in classes){
					if(classes[c].search(self.id+"_gotoSlide") !== -1){
						slide = classes[c].substring(
							classes[c].indexOf("[")+1,
							classes[c].indexOf("]")
						);
					}
				}
				self.goto(slide);
			});	
			
			//fade controls in on hover
			if(this.settings.showControls && this.settings.fadeControlsHover){
				this.e.bind('mouseover',function(){
						$('#'+self.id+'_controls').fadeIn(self.settings.fadeControlsHoverSpeed);
					}).bind('mouseout',function(){
						$('#'+self.id+'_controls').fadeOut(self.settings.fadeControlsHoverSpeed);
					});
			}
			
			//fade pagination in on hover
			if(this.settings.pagination && this.settings.fadePaginationHover){
				this.e.bind('mouseover',function(){
						$('#'+self.id+'_pagination').fadeIn(self.settings.fadePaginationHoverSpeed);
					}).bind('mouseout',function(){
						$('#'+self.id+'_pagination').fadeOut(self.settings.fadePaginationHoverSpeed);
					});
			}
			
			//pause on hover
			if(this.settings.pauseOnHover){
				self.e.bind('mouseover',function(){
						 if(self.playStatus == 1 && self.pausedByHover == 0){
							 self.pausedByHover = 1;
							 self.pause();
						 }
					 })
					 .bind('mouseout',function(){
						  if(self.playStatus == 0  && self.pausedByHover == 1){
							  self.pausedByHover = 0;
							  self.play(1);
						  }
					 });
			}
			
			//mousewheel support
			if(this.settings.mousewheelsupport){
				this.e.mousewheel(function(event,delta) {
					if(delta > 0){ 
						self.movenext(); 
						if(self.settings.callbacks.mousewheelup !== false){
							self.settings.callbacks.mousewheelup(); 
							return false;
						}
					}
					if(delta < 0){ 
						self.moveprev(); 
						if(self.settings.callbacks.mousewheeldown !== false){
							self.settings.callbacks.mousewheeldown();  
							return false; 
						}
					}
				});
			}
		}
	};
	
	$.fn.mbSlider = function(config){
		return this.each(function(){
			if(!this.mbSlider){ 
				this.mbSlider = new mbSlider();
				this.mbSlider.init(this,config);
			}
		});
	};
	
})(jQuery);


//external plugins - jQuery easing and mousewheel support.
(function(){
	
	/*
	 * 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. 
	 *
	*/
	$.extend( $.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;
		}
	});
	
	/*! 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+
	 */
	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);
