var TGAMD = window.TGAMD || {}; TGAMD.ads.sticky = (function($) { var $halfpage = $('#halfpager-art-1'), $page = $('#page'), $primary = $('.primary'), $tertiary = $('.tertiary'), $content = $('#content'), $secondary = $('.secondary'), $stickyRail = ''; var contentOffset = $content.offset().top, tertiaryOffset = $tertiary.offset().top, halfpageHeight = $halfpage.height()+55, primaryHeight = $primary.height(), secondaryHeight = $secondary.height(), stickyRailHeight = ''; var boxPos = tertiaryOffset-halfpageHeight-contentOffset, halfPos = ((tertiaryOffset - halfpageHeight)+35), newPos = halfpageHeight > 600 ? halfPos : boxPos; function init(){ if ( primaryHeight < (secondaryHeight+600) && typeof $.waypoints == 'undefined' ) { return; } $halfpage.nextAll('section').addClass('stickyAd--rail'); $stickyRail = $('.stickyAd--rail'); stickyRailHeight = $stickyRail.height(); $halfpage.waypoint({ handler: function(evt,dir) { $page.toggleClass('stickyAd', dir === 'down'); $stickyRail.css({'top': halfpageHeight+'px'}); if(dir === 'up'){ $stickyRail.removeAttr('style'); } } }); $tertiary.waypoint({ handler: function(evt,dir) { if(dir==='up'){ $halfpage.removeAttr('style'); $stickyRail.css({'position': 'fixed', 'top': halfpageHeight+'px'}); } if(dir==='down'){ $secondary.css({'position': 'relative'}); $halfpage.css({'position': 'absolute','z-index':'inherit','top': boxPos-stickyRailHeight+'px'}); $stickyRail.css({'position': 'absolute','top': newPos+'px'}); } }, offset: halfpageHeight+stickyRailHeight }); } return { init: init }; })(jQuery);