(function($){
	$.fn.verticaltabs=function(options){
		var defaults={
			speed: 500,
			slideShow: true,
			slideShowSpeed: 1000,
			activeIndex: 0,
			playPausePos: "none",
			pauseOnHover: true};
			
		var options=$.extend(defaults, options);
		
		return this.each(function(){
			var verticaltabs = $(this);
			var tabs = $(verticaltabs).children(".verticalslider_tabs").children();
			var contents = $(verticaltabs).children(".verticalslider_contents").children();
			var activeIndex = defaults.activeIndex;
			var slideShow = options.slideShow;
			var timeout;
			var totalHeight;
			
			$(contents[defaults.activeIndex]).addClass("activeContent");
			
			totalHeight=$(".verticalslider_contents li").outerHeight();
			$(".verticalslider_contents li", verticaltabs).css({
				height: totalHeight+"px"
			});
			
			$(".verticalslider_tabs a", verticaltabs).click(function(){
				if (!$(this).parent().hasClass("activeTab")) {
					activeIndex = $(this).parent().prevAll().length;
					
					switchContents();
				
					if (slideShow) {
						clearTimeout(timeout);
						slideShow=false;
					}
				}
				
				return false;
			});
				
			$(tabs).add(contents).hover(function(){
				if(options.pauseOnHover&&slideShow){
					slideShow=!slideShow
				}
			});
			
			function switchContents(){
				$(".activeTab", verticaltabs).removeClass("activeTab");
				$(tabs[activeIndex], verticaltabs).addClass("activeTab");
				
				$(".activeContent", verticaltabs).fadeOut(options.speed).removeClass("activeContent");
				$(contents[activeIndex],verticaltabs).fadeIn(options.speed).addClass("activeContent");
				
			};
				
			function startSlideShow(){
				slideShow=true;
				clearTimeout(timeout);
				timeout=setTimeout(function(){
					autoUpdate();
				},
				options.speed+options.slideShowSpeed)
			}
				
			function autoUpdate(){
				if(slideShow){
					activeIndex++;
					if(activeIndex==contents.length){
						activeIndex=0
					}
					
					switchContents();
					
					startSlideShow();
				}
			};
				
			if(slideShow){
				timeout=setTimeout(function(){
					autoUpdate()
				},
				options.speed+options.slideShowSpeed);
			}
		})
	}
})(jQuery);
