(function ($) {
	jQuery.fn.xfadeChildren = function (options) {
		var settings = jQuery.extend({
			on_class: 'on',
			show_for: 4000,
			speed: 'normal'
		}, options);

		function xfade(from, to) {
			from.fadeOut(settings.speed, function () {
				from.removeClass(settings.on_class);
				to.fadeIn(function () {
					to.addClass(settings.on_class);
				});
			});
		}

		var children = this.children();

		if (children.size() > 1) {
			var pause = false;

			children.filter(':first-child').addClass(settings.on_class);
			children.filter(':not(:first-child)').hide();

			children.hover(function () {
				pause = true;
			}, function () {
				pause = false;
			});

			function run() {
				if (!pause) {
					var from = children.filter('.' + settings.on_class);
					var to = from.next();
					if (to.size() == 0) {
						to = children.eq(0);
					}

					xfade(from, to);
				}

				setTimeout(run, settings.show_for);
			}

			setTimeout(run, settings.show_for);
		}
	};
})(jQuery);
