;(function($) {

    jQuery.fn.preloadImages = function(onload, onlog) {
		
		var log = onlog || function() { };

		var images = $(this);
		images.hide();

		// Set a counter
		var counter = images.length; 
		log("Loading: " + counter + " images"); 

		var cache = [];

		$(images).each(function() {

			var img = document.createElement('img');

			// Load each image, init when all are loaded
			$(img).load(function() {

				log("Loading Image: " + counter); 
				counter--;

				if(counter == 0) {
					images.show();
					onload.apply(images);
				}
			});

			img.src = $(this).attr("src");
			cache.push(img);
		});
	
		return $(this);	

    }; // end plugin

})(jQuery);


