var xFade = new Class({
	
	settings : {
		children : [],
		length : null,
		target : null,
		time : 4000,
		duration : 1000
	},
	
	current : 0,
	firstRun : true,
	
	initialize : function( options )
	{
		
		// APPLY THE SETTINGS PARSED IN
		
		for( var o in options )
			this.settings[o] = options[o];
		
		// THE TARGET REQUIRES A POSITION OF RELATIVE
		
		this.settings.target.setStyles({
			position : 'relative',
			overflow : 'hidden'
		});
		
		// GRAB THE CHILDREN
		
		this.settings.children = this.settings.target.getChildren();
		
		// COUNT
		
		this.settings.length = this.settings.children.length;
		
		$each( this.settings.children, function( item, index )
		{
			
			// GIVE EACH ITEM A POSITION OF ABSOLUTE AND TOP / LEFT
		
			item.setStyles({
				position : 'absolute',
				top : 0,
				left : 0,
				opacity : ( !index ? 100 : 0 )
			})
			
		})
		
		// SHIT HOT LOOKING LINE
		
		this.animate.apply( this ).delay( this.settings.time, this );
			
	},
	
	animate : function()
	{
		
		if( this.firstRun )
		{
			this.firstRun = false;
			return this.animate.bind( this );
		}
		
		// SET UP THE ELEMENTS
		
		var currentElement = this.settings.children[this.current];
		var nextElement = this.settings.children[( this.current == this.settings.length - 1 ? 0 : ( this.current + 1 ) )];
		
		// ANIMATE THEM
		
		new Fx.Morph( currentElement, {
			duration : this.settings.duration
		}).start({
			opacity : 0
		});
		
		new Fx.Morph( nextElement, {
			duration : this.settings.duration
		}).start({
			opacity : 1
		});
		
		// RESET CURRENT
		
		if( this.current == this.settings.length - 1 )
			this.current = 0;
		else
			this.current++;
			
		// RERUN
		
		this.animate.delay( this.settings.time, this );
		
	}
	
})
