jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(f,a,b,c,e){return jQuery.easing[jQuery.easing.def](f,a,b,c,e)},easeInExpo:function(f,a,b,c,e){return a==0?b:c*Math.pow(2,10*(a/e-1))+b},easeOutExpo:function(f,a,b,c,e){return a==e?b+c:c*(-Math.pow(2,-10*a/e)+1)+b},easeInOutExpo:function(f,a,b,c,e){if(a==0)return b;if(a==e)return b+c;if((a/=e/2)<1)return c/2*Math.pow(2,10*(a-1))+b;return c/2*(-Math.pow(2,-10*--a)+2)+b},easeInBack:function(f,a,b,c,e,d){if(d==undefined)d=1.70158;return c* (a/=e)*a*((d+1)*a-d)+b},easeOutBack:function(f,a,b,c,e,d){if(d==undefined)d=1.70158;return c*((a=a/e-1)*a*((d+1)*a+d)+1)+b},easeInOutBack:function(f,a,b,c,e,d){if(d==undefined)d=1.70158;if((a/=e/2)<1)return c/2*a*a*(((d*=1.525)+1)*a-d)+b;return c/2*((a-=2)*a*(((d*=1.525)+1)*a+d)+2)+b}});
/*
 * jQuery tabSlide v1.2.0
 *
 * Copyright(c) Taranets Aleksey
 * www: markup-javascript.com
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */
jQuery.fn.tabSlide = function(_options){
	// defaults options
	var _options = jQuery.extend({
			btPrev: 'a.prev',
			btNext: 'a.next',
			tabs: 'ul.tabset a',
			holderList: 'div',
			scrollElParent: 'ul',
			scrollEl: 'li',
			duration: 1000,
			autoSlide: false,
			startAfterClick:10000,
			otherLinks:false,
			animateContentHeight:false
	},_options)

	return this.each(function(){
		var _this = $(this);

		var _holder = $(_options.holderList, _this);
		var _mover = $(_options.scrollElParent, _holder);
		var _scrollEl = $(_options.scrollEl, _mover);
		var _next = $(_options.btNext,  _this);
		var _prev = $(_options.btPrev,  _this);
		var _tabs = $(_options.tabs,  _this);
		var _otherLinks = $(_options.otherLinks,  _this);

		var _margin = 0;
		var _duration = _options.duration;
		var _current = 0;
		var _step = _holder.innerWidth();
		var _length = _scrollEl.length;
		var _afterTimer = false, _contentHeight, slideHeight = [];


		var _slideTimer = false;
		if (_options.autoSlide) _slideTimer = setInterval(function(){nextSlides()}, _options.autoSlide);
		_scrollEl.each(function(i, slide){
			if (i==0) _contentHeight = $(slide).outerHeight(true);
			slideHeight[i] = $(slide).outerHeight(true);
		});
		_holder.css({'overflow':'hidden','height':_contentHeight});

		if (_options.btNext) {
			_next.click(function(){
				checkAutoScroll();
				nextSlides();
				return false;
			});
		}
		if (_options.btPrev) {
			_prev.click(function(){
				checkAutoScroll();
				_current -= 1;
				if (_current < 0) _current = _length-1;
				_margin = _step*_current;
				animateTab();
				animateHeight(_current);
				setActive();
				return false;
			});
		}
		if (_options.tabs) {
			if (!_tabs.parent().filter('.active').length) {
				_tabs.eq(0).parent().addClass('active');
			}
			_tabs.each(function(i, tabLink){
				if ($(tabLink).parent().hasClass('active')) {
					_margin = _step*i;
					_mover.css({'marginLeft': -_margin})
					_current = i;
				}
			});
			_tabs.click(function(){
				var i = _tabs.index(this);
				checkAutoScroll();
				_tabs.parent().removeClass('active');
				_margin = _step*i;
				animateTab();
				animateHeight(i);
				_current = i;
				$(this).parent().addClass('active');
				return false;
			});
		}
		if (_options.otherLinks) {
			_otherLinks.click(function(){
				checkAutoScroll();
				_current = parseInt(this.href.substr(this.href.indexOf('#')+1))-1;
				_margin = _step*_current;
				animateTab();
				animateHeight(_current);
				setActive();
				return false;
			});
		}
		function checkAutoScroll(){
			if (_slideTimer) clearInterval(_slideTimer);
			if (_afterTimer) clearTimeout(_afterTimer);
			if (_options.autoSlide && _options.startAfterClick) {
				_afterTimer = setTimeout(function(){
					_slideTimer = setInterval(function(){nextSlides()},_options.autoSlide);
				},_options.startAfterClick-_options.autoSlide)
			}
		}
		function nextSlides(){
			_current += 1;
			if (_current >= _length) _current = 0;
			_margin = _step*_current;
			setActive();
			animateTab();
			animateHeight(_current);
			return false;
		}
		function animateTab(){
			_mover.animate({'marginLeft': -_margin}, {duration:_duration, queue:false, easing:'easeOutExpo'});
		}
		function animateHeight(_index){
			if (_options.animateContentHeight) {
				_holder.animate({'height': slideHeight[_index]}, {duration:_duration, queue:false, easing:'easeOutExpo'});
			}
		}
		function setActive () {
			if (_options.tabs) {
				_tabs.parent().removeClass('active');
				_tabs.eq(_current).parent().addClass('active');
			}
		}
	});
}
