;(function($){
	
	var defaults = {
		duration: 500,
		delay: 4000	
	};

	$.fn.crossFade = function(element, options){
		
		var settings = $.extend(defaults, options),
			$container = $(this),
			items = [],
			panels = $container.find('> ' + element),
			panelCount = panels.length,
			currentPanel = 1;
				
		return this.each(function(){
						
			$container.find('> ' + element).each(function () {
				items.push($(this).clone());
	        });
			
			$container
				.css('position', 'relative')
				.find('> ' + element + ':not(:first)')
					.remove();
					
			function crossFade() {
							
				$domElement = $(items[currentPanel]);

				$domElement
					.css({
						opacity: 0,
						position: 'absolute',
						zIndex: 10,
						left: 0,
						top: 0
					})
					.prependTo($container)
					.animate({opacity : 1}, settings.duration);
					
					$container
						.find('> ' + element + ':last')
							.animate({opacity : 0}, settings.duration, function(){
								$(this).remove();
							});
					
					currentPanel++;
					if ( currentPanel >= panelCount ) {
						currentPanel = 0;
					}
					
					window.setTimeout(crossFade, settings.delay);
			}
			window.setTimeout(crossFade, settings.delay);
			
		});
	}
	
})(jQuery);