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