
(function($){
	
    $.preload = function(el, options){
        // To avoid scope issues, use 'base' instead of 'this'
        // to reference this class from internal events and functions.
        var base = this;

        // Access to jQuery and DOM versions of element
        base.$el = $(el);
        base.el = el;

        // Add a reverse reference to the DOM object
        base.$el.data("preload", base);

        base.init = function(){

            base.options = $.extend({},$.preload.defaultOptions, options);

        };

        // Sample Function, Uncomment to use
        // base.functionName = function(paramaters){
        //
        // };

        // Run initializer
        base.init();
    };

    $.preload.defaultOptions = {callback:function(){}};

    $.fn.preload = function(options){
        return this.each(function(){
            (new $.preload(this, options));            
            $.each($(this).find('*'),function(index,item){            
				$bgImg = $(item).css('background-image') || $(item).css('background');				
				var $bgImgUrl = '';
			 	if($bgImg != null && $bgImg != 'none' && $bgImg != ''){
			 	// /[^\/]+\.(gif|jpg|jpeg|png)/g
					$bgImgUrl = $bgImg.replace(/url\((.*)\)/,'$1');
					$bgImgUrl = $bgImgUrl.replace(/"/g,'');
				}
				//$('<img />').attr('src', $bgImgUrl).appendTo('.imager');
				//if(item.src){
				//	$('<img />').attr('src', item.src).appendTo('.imager');
				//}				
            });            
            options.callback();
        });
    };

})(jQuery);
