(function($) {
	// This plugin allows you to preload the background images of any matched elements.
	// By: Dan P. Smith
	$.fn.preloadbackimage = function(options) {
		// This pattern matches the format url(something.gif) for replacement with something.gif
		var pattern = new RegExp('url\\("{0,1}([^"\\)]+)"{0,1}\\)');
		var opts = $.extend({}, $.fn.preloadbackimage.defaults, options);
		return this.each(function() {
			var backgroundImg = $(this).css('background-image');
			if (backgroundImg.match(pattern)) {
				var filename = backgroundImg.replace(pattern,pattern.exec(backgroundImg)[1]);
				$.fn.preloadbackimage.preloadimage(filename);
			}
		});
	};
	// preload a single image from a source
	$.fn.preloadbackimage.preloadimage = function(filename) {
		debug('Preloading Image: '+filename);	
		new Image().src = filename;
		debug('Loaded Image: '+filename);
	};
	// private function for debugging
	function debug(msg) {
		if (window.console && window.console.log)
			window.console.log(msg);
	};
	// plugin defaults
	$.fn.preloadbackimage.defaults = { };
})(jQuery);
