(function($){$.fn.belowfold=function(options){var defaults={delay:5000,duration:5000,width:'183px',height:'48px',bottom:'20px',zIndex:1000,fadeIn:500,fadeOut:500,src:'../media/down-arrow.png',offset:'0px',autoPosition:true};var options=$.extend(defaults,options);var selector=this;var imgWidth=parseFloat((options.width).replace(/[A-z]/ig,''));var imgHeight=parseFloat((options.height).replace(/[A-z]/ig,''));var posBottom=parseFloat((options.bottom).replace(/[A-z]/ig,''));var offset=parseFloat((options.offset).replace(/[A-z]/ig,''));var delay=5000;if(options.delay>delay){delay=options.delay}var scrolled=false;$(window).one('scroll.belowfold',function(){scrolled=true;if(scrolled){$('#belowfold-popup').stop().animate({opacity:'0'})}});window.setTimeout(function(){if(options.autoPosition){$(selector).css({position:'relative'})}var scrollTop=$(window).scrollTop();var windowHeight=$(window).height();var selectorWidth=$(selector).width();var selectorOffset=$(selector).offset();var documentHeight=$(document).height();if(((scrollTop+windowHeight)-documentHeight<-(imgHeight+offset))&&(!scrolled)){$(selector).append('<div id="belowfold-popup"></div>');$('#belowfold-popup').css({background:'url('+options.src+') center center no-repeat',cursor:'pointer',width:imgWidth+'px',height:imgHeight+'px',opacity:0,zIndex:options.zIndex,position:'absolute',left:(Math.floor(selectorWidth/2))-(Math.floor(imgWidth/2)),top:(windowHeight+scrollTop+imgHeight)+'px'}).animate({top:(windowHeight+scrollTop-Math.floor(selectorOffset.top))-(imgHeight+posBottom)+'px',opacity:'1'},options.fadeIn).delay(options.duration).animate({opacity:'0'},options.fadeOut,function(){$(this).remove()})}$(window).bind('resize.belowfold',function(){var selectorNewWidth=(Math.floor($(selector).width()/2))-(Math.floor(imgWidth/2));var newWindowHeight=($(window).height()+$(window).scrollTop())-(imgHeight+posBottom);if(newWindowHeight>documentHeight){$('#belowfold-popup').stop().animate({opacity:'0'})}else{$('#belowfold-popup').css({left:selectorNewWidth+'px',top:newWindowHeight+'px'})}});$('#belowfold-popup').one('click.belowfold',function(){$('#belowfold-popup').stop().animate({opacity:'0'})})},delay)}})(jQuery);
