(function($){
	$.fn.fadeLoad = function(duration) {
		
		return this.each(function() {		
			var container = $(this);
			var images = $('img', container);
			var image_count = images.length;
			if (image_count) {
				var images_loaded = 0;
				container.css({'opacity':'0'});
				images.each(function() {
					var this_src = $(this).attr('src');
					$(this).attr('src','').attr('src', this_src);
					$(this).error(function() {
						$(this).unbind('error').attr('src', "images/error.jpg");
						images_loaded++;
						if (images_loaded==images.length) {
							container.animate({'opacity':'1'}, duration);
						}
					});
					$(this).bind('load', function() {
						images_loaded++;
						if (images_loaded==images.length) {
							container.animate({'opacity':'1'}, duration);
						}
					});
				});
			}
		});
	
	};
})(jQuery);
