
(function($){$.belowthefold=function(element,settings){var fold=$(window).height()+$(window).scrollTop();return fold<=$(element).offset().top-settings.threshold;};$.abovethetop=function(element,settings){var top=$(window).scrollTop();return top>=$(element).offset().top+$(element).height()-settings.threshold;};$.rightofscreen=function(element,settings){var fold=$(window).width()+$(window).scrollLeft();return fold<=$(element).offset().left-settings.threshold;};$.leftofscreen=function(element,settings){var left=$(window).scrollLeft();return left>=$(element).offset().left+$(element).width()-settings.threshold;};$.anybelowthefold=function(element,settings){var fold=$(window).height()+$(window).scrollTop();console.debug("fold %s, bottom %s",fold,$(element).offset().top+$(element).height()-settings.threshold);return fold<=$(element).offset().top+$(element).height()-settings.threshold;};$.anybelowsharebar=function(element,settings){var fold=$(window).height()+$(window).scrollTop()-40;return fold<=$(element).offset().top+$(element).height()-settings.threshold;};$.anyabovethetop=function(element,settings){var top=$(window).scrollTop();return top>=$(element).offset().top-settings.threshold;};$.anyrightofscreen=function(element,settings){var fold=$(window).width()+$(window).scrollLeft();return fold<=$(element).offset().left+$(element).width()-settings.threshold;};$.anyleftofscreen=function(element,settings){var left=$(window).scrollLeft();return left>=$(element).offset().left-settings.threshold;};$.inviewport=function(element,settings){return!$.rightofscreen(element,settings)&&!$.leftofscreen(element,settings)&&!$.belowthefold(element,settings)&&!$.abovethetop(element,settings);};$.allinviewport=function(element,settings){return!$.anyrightofscreen(element,settings)&&!$.anyleftofscreen(element,settings)&&!$.anybelowthefold(element,settings)&&!$.anyabovethetop(element,settings);};$.extend($.expr[':'],{"below-the-fold":function(a,i,m){return $.belowthefold(a,{threshold:0});},"above-the-top":function(a,i,m){return $.abovethetop(a,{threshold:0});},"left-of-screen":function(a,i,m){return $.leftofscreen(a,{threshold:0});},"right-of-screen":function(a,i,m){return $.rightofscreen(a,{threshold:0});},"in-viewport":function(a,i,m){return $.inviewport(a,{threshold:0});},"any-below-the-fold":function(a,i,m){return $.anybelowthefold(a,{threshold:0});},"any-above-the-top":function(a,i,m){return $.anyabovethetop(a,{threshold:0});},"any-left-of-screen":function(a,i,m){return $.anyleftofscreen(a,{threshold:0});},"any-right-of-screen":function(a,i,m){return $.anyrightofscreen(a,{threshold:0});},"all-in-viewport":function(a,i,m){return $.allinviewport(a,{threshold:0});},"all-above-sharebar":function(a,i,m){return!$.anybelowsharebar(a,{threshold:0});},"any-below-sharebar":function(a,i,m){return $.anybelowsharebar(a,{threshold:0});}});})(jQuery);