﻿(function(b){function s(){function h(a,d){t[a](d,function(c){c=="error"?i.push(d):k.push(d)&&g.each(d);o()},"lazy-loaded-"+(g.name?g.name:(new Date).getTime()))}function j(a){g.complete(a,k,i);g[a](a=="error"?i:k);clearTimeout(p);clearTimeout(u)}function o(){if(k.length==l.length)j("success");else k.length+i.length==l.length&&j("error")}function q(){i.push(this.src);o()}var t=this,g,k=[],i=[],p,u,n,l=[];this.init=function(a){if(a){g=b.extend({},b.xLazyLoader.defaults,a);n={js:g.js,css:g.css,img:g.img}; b.each(n,function(d,c){if(typeof c=="string")c=c.split(",");l=l.concat(c)});if(l.length){if(g.timeout)p=setTimeout(function(){var d=k.concat(i);b.each(l,function(c,f){b.inArray(f,d)==-1&&i.push(f)});j("error")},g.timeout);b.each(n,function(d,c){if(b.isArray(c))b.each(c,function(f,e){h(d,e)});else typeof c=="string"&&h(d,c)})}else j("error")}};this.js=function(a,d,c){var f=b('script[src*="'+a+'"]');if(f.length)f.attr("pending")?f.bind("scriptload",d):d();else{var e=document.createElement("script"); e.setAttribute("type","text/javascript");e.setAttribute("src",a);e.setAttribute("id",c);e.setAttribute("pending",1);e.onerror=q;b(e).bind("scriptload",function(){b(this).removeAttr("pending");d();setTimeout(function(){b(e).unbind("scriptload")},10)});var r=false;e.onload=e.onreadystatechange=function(){if(!r&&(!this.readyState||/loaded|complete/.test(this.readyState))){r=true;e.onload=e.onreadystatechange=null;b(e).trigger("scriptload")}};m.appendChild(e)}};this.css=function(a,d,c){if(b('link[href*="'+ a+'"]').length)d();else{var f=b('<link rel="stylesheet" type="text/css" media="all" href="'+a+'" id="'+c+'"></link>')[0];if(b.browser.msie)f.onreadystatechange=function(){/loaded|complete/.test(f.readyState)&&d()};else if(b.browser.opera)f.onload=d;else{c=location.hostname.replace("www.","");a=/http:/.test(a)?/^(\w+:)?\/\/([^\/?#]+)/.exec(a)[2]:c;c!=a&&b.browser.mozilla?d():function(){d()}()}m.appendChild(f)}};this.img=function(a,d){var c=new Image;c.onload=d;c.onerror=q;c.src=a};this.disable=function(a){b("#lazy-loaded-"+ a,m).attr("disabled","disabled")};this.enable=function(a){b("#lazy-loaded-"+a,m).removeAttr("disabled")};this.destroy=function(a){b("#lazy-loaded-"+a,m).remove()}}b.xLazyLoader=function(h,j){if(typeof h=="object"){j=h;h="init"}(new s)[h](j)};b.xLazyLoader.defaults={js:[],css:[],img:[],name:null,timeout:2E5,success:function(){},error:function(){},complete:function(){},each:function(){}};var m=document.getElementsByTagName("head")[0]})(jQuery);
