(function(b){var a="waitForImages";b.waitForImages={hasImageProperties:["backgroundImage","listStyleImage","borderImage","borderCornerImage"]};b.expr[":"].uncached=function(d){var c=document.createElement("img");c.src=d.src;return b(d).is('img[src!=""]')&&!c.complete};b.fn.waitForImages=function(e,c,d){if(b.isPlainObject(arguments[0])){c=e.each;d=e.waitForAll;e=e.finished}e=e||b.noop;c=c||b.noop;d=!!d;if(!b.isFunction(e)||!b.isFunction(c)){throw new TypeError("An invalid callback was supplied.")}return this.each(function(){var j=b(this),k=[];if(d){var f=b.waitForImages.hasImageProperties||[],i=/url\((['"]?)(.*?)\1\)/g;j.find("*").each(function(){var l=b(this);if(l.is("img:uncached")){k.push({src:l.attr("src"),element:l[0]})}b.each(f,function(o,p){var m=l.css(p);if(!m){return true}var n;while(n=i.exec(m)){k.push({src:n[2],element:l[0]})}})})}else{j.find("img:uncached").each(function(){k.push({src:this.src,element:this})})}var h=k.length,g=0;if(h==0){e.call(j[0])}b.each(k,function(m,l){var n=new Image;b(n).bind("load."+a+" error."+a,function(o){g++;c.call(l.element,g,h,o.type=="load");if(g==h){e.call(j[0]);return false}});n.src=l.src})})}})(jQuery);
