(function($)
{
	$.fn.xFade = function( options )
	{
		var settings = {
			children:[],
			length:null,
			time:8000,
			duration:1500
		}
		var firstRun = true;
		var current = 0;
		for( var o in options )
		{
			settings[o] = options[o];
		}
		this.css({
			position:'relative',
			overflow:'hidden'
		});
		settings.children = this.children();
		settings.length = settings.children.length;
		current = 0;
		$.each( settings.children, function( index, value )
		{
			var v = $(value);
			v.css({
				position:'absolute',
				top:0,
				left:0
			});
			if( index > 0 )
			{
				v.parent().prepend( v );
			}
		});
		this.fade = function()
		{
			var currentElement = $(settings.children[current]);
			var nextElement = $(settings.children[( current == settings.length - 1 ? 0 : ( current + 1 ) )]);
			currentElement.animate({
				opacity:0
			}, settings.duration, function()
			{
				currentElement.parent().prepend( currentElement );
				currentElement.css('opacity',1);
			});
			if( current == settings.length - 1 )
			{
				current = 0;
			} else {
				current++;
			}
			this.fade.moo_delay( settings.time, this );
		};
		this.fade.moo_delay( settings.time, this );
	};
	
})(jQuery);
