//* jquery tabs *********************************************************************************
jQuery.fn.jqueryTabs = function(_options){
	// defaults options
/*
		event: 'click','mouseover','mouseleave'
*/
	var _options = jQuery.extend({
		event: 'click',
		autoSwitch: false,
		tabset: 'ul.tabset'
	},_options);

	return this.each(function(){
		var holder = this;
		holder.aswitch = _options.autoSwitch;
		holder.pause = false;
		var _t = null;
		var _this = jQuery(this);
		var _tabset = jQuery(_options.tabset,_this);

		_tabset.each(function(){
			var _list = $(this);
			var _links = _list.find('a.tab', _list);
			var _a = _links.index(_links.filter('.active'));
			if(_a==-1) _links.eq(_a).addClass('active');

			_this.mouseenter(function(){
				holder.pause = true;
				if(_t) clearTimeout(_t);
			}).mouseleave(function(){
				holder.pause = false;
				if(holder.aswitch && !holder.pause){
					_t = setTimeout(function(){
						if(_a < _links.length-1) _a++;
						else _a = 0;
						_links.eq(_a).trigger(_options.event);
					},holder.aswitch);
				};
			});
			if(holder.aswitch && !holder.pause){
				_t = setTimeout(function(){
					if(_a < _links.length-1) _a++;
					else _a = 0;
					_links.eq(_a).trigger(_options.event);
				},holder.aswitch);
			};
			_links.each(function(){
				var _link = $(this);
				var _href = _link.attr('href');
				var _tab = $(_href, _this);

				if(_link.hasClass('active')) _tab.show();
				else _tab.hide();

				_link.bind(_options.event, function(){
					change(_links.index(this));
					return false;
				});

				function change(next){
					_a = next;
					if(_t) clearTimeout(_t);
					_links.filter('.active').each(function(){
						$($(this).removeClass('active').attr('href')).hide();
					});
					_link.addClass('active');
					_tab.show();

					if(holder.aswitch && !holder.pause){
						_t = setTimeout(function(){
							if(_a < _links.length-1) _a++;
							else _a = 0;
							_links.eq(_a).trigger(_options.event);
						},holder.aswitch);
					};
				}
			});
		});
	})
}

jQuery.fn.vvAccordion = function(_options){
	var _options = jQuery.extend({
		el: '> li',
		head: 'a.opener',
		content: 'div.ac-content',
		active: 'selected',
		event: 'click',
		onBeforeAply: null,
		onChangeStart: null,
		onChange: null,
		onMade: null,
		duration: 400
	},_options);
	return this.each(function(){
		var _this = this;
		var _t = null;
		_this.duration = _options.duration;
		_this.list = $(_options.el, _this);
		_this.list.each(function(i){
			this.opener = $(_options.head, this);
			this.slider = $(_options.content, this);
			this.width = parseInt(this.slider.css('width'),10);
			this.height = $(this).height();
			if($(this).hasClass(_options.active)){
				_this.active = this;
			};
			this.index = i;
		});
		if(!_this.active) _this.active = null;
		if(jQuery.isFunction(_options.onBeforeAply)){
			_options.onBeforeAply.apply(_this);
		};
		_this.list.each(function(){
			$(this).css({width: '0px'});
		});
		if(_this.active) $(_this.active).css('width','');
		_this.list.each(function(){
			var next = this;
			this.opener.bind(_options.event, function(){
				_this.list.find(_options.head).removeClass(_options.active).eq(_this.list.find(_options.head).index(this)).addClass(_options.active);
				if(jQuery.isFunction(_options.onChangeStart)){
					_options.onChangeStart.apply(_this.active);
				};
				if(_t) clearTimeout(_t);
				_t = setTimeout(function(){
					_this.curent = next;
					$(next).animate({width: next.width},{duration: _options.duration,
					step:function(i, curObj){
						var _p = curObj.now/curObj.end;
						if(_this.active !== next){
							var _thisValue = 0;
							if (curObj.prop == 'height') {
								_thisValue = _this.active.height - (_this.active.height * _p);
							}else{
								_thisValue = curObj.end - curObj.now;
							}
							eval('$(_this.active).css({'+curObj.prop+':'+_thisValue+'})');
						}
					},
					complete: function(){
						$(_this.active).removeClass(_options.active);
						$(_this.active).css({width: 0});
						_this.active = next;
						$(_this.active).addClass(_options.active);
						$(_this.active).css({width: _this.active.width});
						if(jQuery.isFunction(_options.onChange)){
							_options.onChange.apply(_this.active);
						};
						_this.curent = false;
					}});
				},150);
				return false;
			});
			if(_options.event=='mouseenter'){
				_this.list.parent().mouseleave(function(){
					$(_this.active).animate({width: 0},{duration: _options.duration});
					_this.list.find(_options.head).removeClass(_options.active);
					_this.active = null;
				});
			}
		});
		if(jQuery.isFunction(_options.onMade)){
			_options.onMade.apply(_this);
		};
	});
}

$(document).ready(function(){
	$('.features-tabs').jqueryTabs({
		event: 'mouseenter',
		autoSwitch: 10000
	})
});
