/**
 *	preload - jQuery plugin
 *	
 *	use the fitWin() method to preload images.  
 *  
 *	@author martin glaß <mglass at 3-point dot de>
 *	@version 0.1
 */

var $imgs = {};
(function($) {
	$.fn.preload = function($options) {
	  $options = $.extend({
			'debug': false
		}, $options);
		var log = function(message) {
			if(window.console && $options.debug) console.log(message);
		}
		
		/**
		 * work with every form in the selection
		 */
		return this.each(function() {
			
			el = $(this);
			var $filename = el.attr('src').replace(/_k/, '_g');
			var $name = $filename.match(/\/([^\/]+)$/i)[1];
			//console.log($name);
			$imgs[$name] = parseInt(new Date().getTime()/1000);
			$('<img />').attr('src', $filename).load(function() {
			  var $name = $(this).attr('src').match(/\/([^\/]+)$/i)[1];
				var $secs = parseInt(new Date().getTime()/1000) - $imgs[$name];
				log('finished loading '+$filename+' in '+$secs+' seconds');
			});

		});
		
	}
})(jQuery);  
