!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof module&&module.exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){var e=Array.prototype.slice,n=Array.prototype.splice,r={topSpacing:0,bottomSpacing:0,className:"is-sticky",wrapperClassName:"sticky-wrapper",center:!1,getWidthFrom:"",widthFromWrapper:!0,responsiveWidth:!0,zIndex:"auto"},i=t(window),o=t(document),s=[],c=i.height(),a=function(){for(var e=i.scrollTop(),n=o.height(),r=n-c,a=e>r?r-e:0,p=0,d=s.length;d>p;p++){var l=s[p],u=l.stickyWrapper.offset().top,h=u-l.topSpacing-a;if(l.stickyWrapper.css("height",l.stickyElement.outerHeight()),h>=e)null!==l.currentTop&&(l.stickyElement.css({width:"",position:"",top:"","background-color":"","border-bottom":"","z-index":""}),l.stickyElement.parent().removeClass(l.className),l.stickyElement.trigger("sticky-end",[l]),l.currentTop=null);else{var g=n-l.stickyElement.outerHeight()-l.topSpacing-l.bottomSpacing-e-a;if(0>g?g+=l.topSpacing:g=l.topSpacing,l.currentTop!==g){var m;l.getWidthFrom?m=t(l.getWidthFrom).width()||null:l.widthFromWrapper&&(m=l.stickyWrapper.width()),null==m&&(m=l.stickyElement.width()),l.stickyElement.css("width",m).css("position","fixed").css("top",g).css("left","").css("background-color","").css("border-bottom","none").css("z-index",l.zIndex),l.stickyElement.parent().addClass(l.className),null===l.currentTop?l.stickyElement.trigger("sticky-start",[l]):l.stickyElement.trigger("sticky-update",[l]),l.currentTop===l.topSpacing&&l.currentTop>g||null===l.currentTop&&g<l.topSpacing?l.stickyElement.trigger("sticky-bottom-reached",[l]):null!==l.currentTop&&g===l.topSpacing&&l.currentTop<g&&l.stickyElement.trigger("sticky-bottom-unreached",[l]),l.currentTop=g}var f=l.stickyWrapper.parent(),y=l.stickyElement.offset().top+l.stickyElement.outerHeight()>=f.offset().top+f.outerHeight()&&l.stickyElement.offset().top<=l.topSpacing;y?l.stickyElement.css("position","absolute").css("top","").css("bottom",0).css("background-color","").css("z-index",""):l.stickyElement.css("position","fixed").css("top",g).css("bottom","").css("background-color","#fdfdfd").css("border-bottom","3px solid #ddd").css("z-index",l.zIndex)}}},p=function(){c=i.height();for(var e=0,n=s.length;n>e;e++){var r=s[e],o=null;r.getWidthFrom?r.responsiveWidth&&(o=t(r.getWidthFrom).width()):r.widthFromWrapper&&(o=r.stickyWrapper.width()),null!=o&&r.stickyElement.css("width",o)}},d={init:function(e){return this.each(function(){var n=t.extend({},r,e),i=t(this),o=i.attr("id"),c=o?o+"-"+r.wrapperClassName:r.wrapperClassName,a=t("<div></div>").attr("id",c).addClass(n.wrapperClassName);i.wrapAll(function(){return 0==t(this).parent("#"+c).length?a:void 0});var p=i.parent();n.center&&p.css({width:i.outerWidth(),marginLeft:"auto",marginRight:"auto"}),"right"===i.css("float")&&i.css({"float":"none"}).parent().css({"float":"right"}),n.stickyElement=i,n.stickyWrapper=p,n.currentTop=null,s.push(n),d.setWrapperHeight(this),d.setupChangeListeners(this)})},setWrapperHeight:function(e){var n=t(e),r=n.parent();r&&r.css("height",n.outerHeight())},setupChangeListeners:function(t){if(window.MutationObserver){var e=new window.MutationObserver(function(e){(e[0].addedNodes.length||e[0].removedNodes.length)&&d.setWrapperHeight(t)});e.observe(t,{subtree:!0,childList:!0})}else window.addEventListener?(t.addEventListener("DOMNodeInserted",function(){d.setWrapperHeight(t)},!1),t.addEventListener("DOMNodeRemoved",function(){d.setWrapperHeight(t)},!1)):window.attachEvent&&(t.attachEvent("onDOMNodeInserted",function(){d.setWrapperHeight(t)}),t.attachEvent("onDOMNodeRemoved",function(){d.setWrapperHeight(t)}))},update:a,unstick:function(e){return this.each(function(){for(var e=this,r=t(e),i=-1,o=s.length;o-->0;)s[o].stickyElement.get(0)===e&&(n.call(s,o,1),i=o);-1!==i&&(r.unwrap(),r.css({width:"",position:"",top:"","float":"","background-color":"","border-bottom":"","z-index":""}))})}};window.addEventListener?(window.addEventListener("scroll",a,!1),window.addEventListener("resize",p,!1)):window.attachEvent&&(window.attachEvent("onscroll",a),window.attachEvent("onresize",p)),t.fn.sticky=function(n){return d[n]?d[n].apply(this,e.call(arguments,1)):"object"!=typeof n&&n?void t.error("Method "+n+" does not exist on jQuery.sticky"):d.init.apply(this,arguments)},t.fn.unstick=function(n){return d[n]?d[n].apply(this,e.call(arguments,1)):"object"!=typeof n&&n?void t.error("Method "+n+" does not exist on jQuery.sticky"):d.unstick.apply(this,arguments)},t(function(){setTimeout(a,0)})});