/*
 * jQuery tabSlideVert v1.0.0 
 *
 */
jQuery.fn.tabSlideVert = function(_options){
	// defaults options
	var _options = jQuery.extend({
		btPrev: 'a.link-prev',
		btNext: 'a.link-next',
		tabsNews: 'ul.tabs a',
		holderList: 'div',
		scrollElParent: 'ul',
		scrollEl: 'li',
		duration: 1000,
		autoSlide: false
	},_options)

	return this.each(function(){
		var _this = $(this);
		var _lenghtSlide = $(_options.scrollEl, $(_options.holderList, _this)).length;
		var _gHeight = $(_options.holderList, _this).innerHeight();
		var _liHeight = $(_options.scrollEl, $(_options.holderList, _this)).outerHeight();
		var _liSum = $(_options.scrollEl, $(_options.holderList, _this)).length * _liHeight;
		var _rightArrow = $(_options.btNext,  _this);
		var _leftArrow = $(_options.btPrev,  _this);
		var _tabs = $(_options.tabsNews,  _this);
		var _scrollEl = $(_options.scrollElParent, $(_options.holderList, _this));
		var _margin = 0;
		var _duration = _options.duration;
		var f = 0;
		var _current = 0;
		var _step = _gHeight;
		var _length = $(_options.tabsNews,  _this).length;
		var _slideTimer = false;
		
		_this.hover(function(){
			if (_slideTimer) clearTimeout(_slideTimer);
		}, function(){
			if (_options.autoSlide) _slideTimer = setTimeout(function(){_this.autoSlide()}, _options.autoSlide);
		});
		_this.bind('mousemove', function(){if (_slideTimer) clearTimeout(_slideTimer);});
		
		
		$(_scrollEl).css({marginTop: -(_step*(_length-1))})
							 
		_this.nextSlide = function() {
			_current += 1;
			if (_current > _length -1) _current = 0;
			if (_slideTimer) clearTimeout(_slideTimer);
			$(_scrollEl).animate({marginTop: -(_step*(_length-_current-1))+"px"}, {queue:false, duration: _duration, easing: 'easeOutExpo'});
			$(_tabs).removeClass("active");
			$(_tabs).eq(_current).addClass("active");
			if (_options.autoSlide) _slideTimer = setTimeout(function(){_this.autoSlide()}, _options.autoSlide);
			return false;
		}
		if (_options.btNext) {
			$(_rightArrow).click(_this.nextSlide);
		}
		if (_options.btPrev) {
			$(_leftArrow).click(function(){
				_current -= 1;
				if (_current < 0) _current = _length-1;
				if (_slideTimer) clearTimeout(_slideTimer);
				$(_scrollEl).animate({marginTop: -(_step*(_length-_current-1))+"px"}, {queue:false, duration: _duration, easing: 'easeOutExpo'});
				$(_tabs).removeClass("active");
				$(_tabs).eq(_current).addClass("active");
				if (_options.autoSlide) _slideTimer = setTimeout(function(){_this.autoSlide()}, _options.autoSlide);
				return false;
			});
		}
		if (_options.tabsNews) {
			$(_tabs).click(function(){
				if (_slideTimer) clearTimeout(_slideTimer);
				$(_tabs).removeClass("active");
				var _gn = $(_tabs).index($(this));
				_current = _gn;
				_margin = _step*(_length-_current-1);
				$(_scrollEl).animate({marginTop: -_margin + "px"}, {queue:false, duration: _duration, easing: 'easeOutExpo'});
				$(this).addClass("active");
				if (_options.autoSlide) _slideTimer = setTimeout(function(){_this.autoSlide()}, _options.autoSlide);
				return false;
			});
		}
		if (_options.autoSlide) {
			_this.autoSlide = function() {
				_this.nextSlide();
			}
			_slideTimer = setTimeout(function(){_this.autoSlide()}, _options.autoSlide);
		}
	});
}

$(document).ready(function(){
	$('div.column').slideNews({
		btNext:'a.next',
		btPrev:'a.prev',
		tabsNews:'ul.nav a',
		holderList: 'div.slider-holder',
		scrollElParent: 'ul.slider-ul',
		scrollEl: 'li.slide',
		autoSlide: 3000
	});
});
