$().ready( function() {
	$.fn.progFade = function( options ) {  
		var defaults = {
			delay: 1,
			fxTime: 1,
			zIndex: 0,
			firstInstant: true
		};  
		var cnt = this;
		options = $.extend(defaults, options); 		
		
		function slowDrawImage( ) { 
			var rnd = Math.random();
			if( options.imagesList && options.imagesList.length ) {
				rndIndex = Math.floor( options.imagesList.length * rnd );
				newImg = new Image();
				newImg.src = options.imagesList.splice(rndIndex, 1)[0];
				newImg.style.display = 'none';
				
				cnt.append(newImg);
				curImg = $(newImg);
				curImg.animate({ opacity: 'show' }, options.fxTime * 1000 );
			}
			else {
				allImgs = $('img', cnt);
				rndIndex = Math.floor( ( allImgs.length - 1) * rnd );
				allImgs.eq(rndIndex).hide().appendTo(cnt).animate({ opacity: 'show' }, options.fxTime * 1000 );
			}
		}
		
		if (options.firstInstant) { slowDrawImage (options); }
		setInterval ( slowDrawImage, options.delay * 1000, options );
		return this;
	}
});

