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