jQuery.fn.slider = function(options) {
		var currentIndex;
		var obj;
		var t;
		var sliding = null;
		var settings = null;


		if (!options.slideClass || options.slideClass == "") {
				var error = new Error();
				error.message = "No slide class has been supplied";
		}

		settings = options;

		if (!options.slideDuration || !parseInt(options.slideDuration)) {
				options.slideDuration = 4000;
		}

		if (!options.slideOffet || !parseInt(options.slideOffet)) {
				options.slideOffet = '500px';
		}

		if (!options.fadeOutDuration || !parseInt(options.fadeOutDuration)) {
				options.fadeOutDuration = 4000;
		}

		if (!options.fadeInDuration || !parseInt(options.fadeInDuration)) {
				options.fadeInDuration = 4000;
		}

		return this.each(function() {
				$(options.slideClass, this).hide();
				$(options.slideClass + ":eq(0)", this).show();
				currentIndex = 0;
				obj = this;
				t = setTimeout(function(){ slide(); }, settings.slideDuration);
		});
		
		function slide(speed)
		{
				clearTimeout(t);
				if(!sliding) {
						sliding = true;
						var current = $(settings.slideClass + ":eq(" + currentIndex + ")", obj);
						currentIndex++;
						if (currentIndex > $(settings.slideClass, obj).size() - 1) {
								currentIndex = 0;
						}
						var next = 	$(settings.slideClass + ":eq(" + currentIndex + ")", obj);
						next.show('slide', { direction: "up" }, settings.fadeInDuration);
						current.hide('slide', { direction: "down" }, settings.fadeOutDuration, function(){
								sliding = false;
								t = setTimeout(function(){ slide(settings.fadeOutDuration); }, settings.slideDuration);
								$(settings.slideClass + ":eq(" + currentIndex + ")", obj).css('z-index', 1);
						});
				}
		}

		function slideBack(speed)
		{
				clearTimeout(t);
				if(!sliding) {
						sliding = true;
						var current = $(settings.slideClass + ":eq(" + currentIndex + ")", obj);
						
						currentIndex--;
						if (currentIndex < 0) {
								currentIndex = $(settings.slideClass, obj).size() - 1;
						}
						var next = 	$(settings.slideClass + ":eq(" + currentIndex + ")", obj);
						
						next.show('slide', { direction: "down" }, settings.fadeInDuration);
						current.hide('slide', { direction: "up" }, settings.fadeOutDuration, function(){
								sliding = false;
								t = setTimeout(function(){ slide(settings.fadeOutDuration); }, settings.slideDuration);
								$(settings.slideClass + ":eq(" + currentIndex + ")", obj).css('z-index', 1);
						});

				}
		}
};
