(function($) {
    $.fn.carousel = function(options) {
        var defaults = {
			display: 1,
			intervaltime: 3000,
			duration: 350
		};
		
		var options = $.extend(defaults, options);
		
		var oSlider = $(this);
		var oContent = $('.overview', oSlider);
		var oPages = oContent.children();
		var oTimer, oCurrent, iCurrent, iSteps;
		
		return this.each(function() {
			initialize();
		});
		
		function initialize() {
			iCurrent = 1;
			iSteps = Math.max(1, Math.ceil(oPages.length / options.display));
			
			if(iSteps > 1) {
				setDisplay();
				setTimer(true);
			}
		}
		
		function setDisplay() {
			for(i=0; i<oPages.length; i++) {
				if(i != 0) {
					$(oPages[i]).css('display', 'none');
				}
			}
		}
		
		function setTimer(bReset) {
			if(bReset){
				clearInterval(oTimer);
				oTimer = window.setInterval(function(){
					changeSlide();
				}, options.intervaltime);
			}
		}
		
		function changeSlide() {
			if(iSteps > 1) {
				$(oPages[iCurrent-1]).fadeOut(options.duration, function() {
					iCurrent = (iCurrent < iSteps) ? iCurrent+1 : 1
					$(oPages[iCurrent-1]).fadeIn(options.duration, function() {
						setTimer(true);
					});
				});
			}
		}
    };
})(jQuery);
