// Sticky Plugin v1.0.3 for jQuery
// =============
// Author: Anthony Garand
// Improvements by German M. Bravo (Kronuz) and Ruud Kamphuis (ruudk)
// Improvements by Leonardo C. Daronco (daronco)
// Created: 02/14/2011
// Date: 07/20/2015
// Website: http://stickyjs.com/
// Description: Makes an element on the page stick on the screen as you scroll
//              It will only set the 'top' and 'position' of your element, you
//              might need to adjust the width in some cases.

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