(function($){ $.fn.rotator = function(options){
    var defaults = {
		ms: 4000,
		n: 0,
		autoHeight: false
	};
    var options = $.extend(defaults, options);
	var aktivInterval;
	var startHtml = $('.rotator .picwrapper').html();
	$('.rotator .linkwrapper a').hoverIntent(function(){
		$('.rotator .picwrapper').html(startHtml);											  
		window.clearInterval(aktivInterval);
		$('.rotator .linkwrapper a').removeClass('aktiv');
		var str = $(this).attr('class');
		str = str.replace(/\D/gi,'');
		str = parseInt(str.substr(0,str.length - 1));
		$(this).addClass('aktiv');
		$('.rotator .picwrapper').animate({scrollTop: 140*(str-1) +"px"},700, function(){
		});
		},function(){
		});
	
	return this.each(function(index) {
		var $this = $(this);
		var initialHeight = 0;
		$this.children().filter(":lt("+options.n+")").each(function(index,item){
		    initialHeight += $(item).height();
		});
		$this.height(initialHeight);
		function doRotate() {
			aktivInterval = setInterval(function(){
				var childHeight = $this.children().filter(":first-child").height();
				var childClass = $this.children().filter(":first-child").attr('class');
				var animParams = {scrollTop: (childHeight) + "px"};
				var autoHeight = 0;
				$this.children().filter(":lt("+(options.n+1)+")").each(function(index,item){
					if(index>0)autoHeight += $(item).height();
				});
				$('.rotator .linkwrapper a').removeClass('aktiv');
				$('.rotator .linkwrapper .'+childClass).addClass('aktiv');
				
				if(options.autoHeight)animParams = $.extend({height:(autoHeight) + "px"}, animParams);
				$this.animate(animParams, 700, function(){
					$this.scrollTop(0);
					$this.append($this.children().filter(":first-child"));
					$this.css("overflow","hidden");
				});	
			}, options.ms);
		}
		doRotate();
		$(".rotator").mouseout(function(){
			window.clearInterval(aktivInterval);						
			doRotate();
		})
	
	});
}})(jQuery);
