(function(a){a.fn.lazyload=function(d){var b={threshold:0,failurelimit:0,event:"scroll",effect:"show",container:window};d&&a.extend(b,d);var c=this;"scroll"==b.event&&a(b.container).bind("scroll",function(){var d=0;c.each(function(){if(!(a.abovethetop(this,b)||a.leftofbegin(this,b)))if(!a.belowthefold(this,b)&&!a.rightoffold(this,b))a(this).trigger("appear");else if(d++>b.failurelimit)return false});var e=a.grep(c,function(a){return!a.loaded});c=a(e)});this.each(function(){var c=this;undefined==a(c).attr("original")&&a(c).attr("original",a(c).attr("src"));if("scroll"!=b.event||undefined==a(c).attr("src")||b.placeholder==a(c).attr("src")||(a.abovethetop(c,b)||a.leftofbegin(c,b)||a.belowthefold(c,b)||a.rightoffold(c,b))){if(b.placeholder)a(c).attr("src",b.placeholder);else a(c).removeAttr("src");c.loaded=false}else c.loaded=true;a(c).one("appear",function(){!this.loaded&&a("<img />").bind("load",function(){a(c).hide().attr("src",a(c).attr("original"))[b.effect](b.effectspeed);c.loaded=true}).attr("src",a(c).attr("original"))});"scroll"!=b.event&&a(c).bind(b.event,function(){!c.loaded&&a(c).trigger("appear")})});a(b.container).trigger(b.event);return this};a.belowthefold=function(c,b){if(b.container===undefined||b.container===window)var d=a(window).height()+a(window).scrollTop();else var d=a(b.container).offset().top+a(b.container).height();return d<=a(c).offset().top-b.threshold};a.rightoffold=function(c,b){if(b.container===undefined||b.container===window)var d=a(window).width()+a(window).scrollLeft();else var d=a(b.container).offset().left+a(b.container).width();return d<=a(c).offset().left-b.threshold};a.abovethetop=function(c,b){if(b.container===undefined||b.container===window)var d=a(window).scrollTop();else var d=a(b.container).offset().top;return d>=a(c).offset().top+b.threshold+a(c).height()};a.leftofbegin=function(c,b){if(b.container===undefined||b.container===window)var d=a(window).scrollLeft();else var d=a(b.container).offset().left;return d>=a(c).offset().left+b.threshold+a(c).width()};a.extend(a.expr[":"],{"below-the-fold":"$.belowthefold(a, {threshold : 0, container: window})","above-the-fold":"!$.belowthefold(a, {threshold : 0, container: window})","right-of-fold":"$.rightoffold(a, {threshold : 0, container: window})","left-of-fold":"!$.rightoffold(a, {threshold : 0, container: window})"})})(jQuery)
