﻿(function($) { $.scrollFollow = function(g, h) { g = $(g); var i = g.css('position'); function ani() { g.queue([]); var a = parseInt($(window).height()); var b = parseInt($(document).scrollTop()); var c = parseInt(g.cont.offset().top); var d = parseInt(g.cont.attr('offsetHeight')); var e = parseInt(g.attr('offsetHeight') + (parseInt(g.css('marginTop')) || 0) + (parseInt(g.css('marginBottom')) || 0)); var f; if (j) { if (h.relativeTo == 'top') { if (g.initialOffsetTop >= (b + h.offset)) { f = g.initialTop } else { f = Math.min((Math.max((-c), (b - g.initialOffsetTop + g.initialTop)) + h.offset), (d - e - g.paddingAdjustment)) } } else if (h.relativeTo == 'bottom') { if ((g.initialOffsetTop + e) >= (b + h.offset + a)) { f = g.initialTop } else { f = Math.min((b + a - e - h.offset), (d - e)) } } if ((new Date().getTime() - g.lastScroll) >= (h.delay - 20)) { g.animate({ top: f }, h.speed, h.easing) } } }; var j = true; if ($.cookie != undefined) { if ($.cookie('scrollFollowSetting' + g.attr('id')) == 'false') { var j = false; $('#' + h.killSwitch).text(h.offText).toggle(function() { j = true; $(this).text(h.onText); $.cookie('scrollFollowSetting' + g.attr('id'), true, { expires: 365, path: '/' }); ani() }, function() { j = false; $(this).text(h.offText); g.animate({ top: g.initialTop }, h.speed, h.easing); $.cookie('scrollFollowSetting' + g.attr('id'), false, { expires: 365, path: '/' }) }) } else { $('#' + h.killSwitch).text(h.onText).toggle(function() { j = false; $(this).text(h.offText); g.animate({ top: g.initialTop }, 0); $.cookie('scrollFollowSetting' + g.attr('id'), false, { expires: 365, path: '/' }) }, function() { j = true; $(this).text(h.onText); $.cookie('scrollFollowSetting' + g.attr('id'), true, { expires: 365, path: '/' }); ani() }) } } if (h.container == '') { g.cont = g.parent() } else { g.cont = $('#' + h.container) } g.initialOffsetTop = parseInt(g.offset().top); g.initialTop = parseInt(g.css('top')) || 0; if (g.css('position') == 'relative') { g.paddingAdjustment = parseInt(g.cont.css('paddingTop')) + parseInt(g.cont.css('paddingBottom')) } else { g.paddingAdjustment = 0 } $(window).scroll(function() { $.fn.scrollFollow.interval = setTimeout(function() { ani() }, h.delay); g.lastScroll = new Date().getTime() }); $(window).resize(function() { $.fn.scrollFollow.interval = setTimeout(function() { ani() }, h.delay); g.lastScroll = new Date().getTime() }); g.lastScroll = 0; ani() }; $.fn.scrollFollow = function(a) { a = a || {}; a.relativeTo = a.relativeTo || 'top'; a.speed = a.speed || 500; a.offset = a.offset || 0; a.easing = a.easing || 'swing'; a.container = a.container || this.parent().attr('id'); a.killSwitch = a.killSwitch || 'killSwitch'; a.onText = a.onText || 'Turn Slide Off'; a.offText = a.offText || 'Turn Slide On'; a.delay = a.delay || 0; this.each(function() { new $.scrollFollow(this, a) }); return this } })(jQuery);

