!function(n,t){"use strict";"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():n.Headroom=t()}(this,function(){"use strict";function i(n){this.callback=n;this.ticking=!1}function u(n){return n&&"undefined"!=typeof window&&(n===window||n.nodeType)}function r(n){var t,f,i,e;if(arguments.length<=0)throw new Error("Missing arguments in extend function");for(i=n||{},f=1;f<arguments.length;f++){e=arguments[f]||{};for(t in e)i[t]="object"!=typeof i[t]||u(i[t])?i[t]||e[t]:r(i[t],e[t])}return i}function f(n){return n===Object(n)?n:{down:n,up:n}}function n(t,i){i=r(i,n.options);this.lastKnownScrollY=0;this.elem=t;this.tolerance=f(i.tolerance);this.classes=i.classes;this.offset=i.offset;this.scroller=i.scroller;this.initialised=!1;this.onPin=i.onPin;this.onUnpin=i.onUnpin;this.onTop=i.onTop;this.onNotTop=i.onNotTop;this.onBottom=i.onBottom;this.onNotBottom=i.onNotBottom}var t={bind:!!function(){}.bind,classList:"classList"in document.documentElement,rAF:!!(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame)};return window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,i.prototype={constructor:i,update:function(){this.callback&&this.callback();this.ticking=!1},requestTick:function(){this.ticking||(requestAnimationFrame(this.rafCallback||(this.rafCallback=this.update.bind(this))),this.ticking=!0)},handleEvent:function(){this.requestTick()}},n.prototype={constructor:n,init:function(){if(n.cutsTheMustard)return(this.debouncer=new i(this.update.bind(this)),this.elem.classList.add(this.classes.initial),setTimeout(this.attachEvent.bind(this),100),this)},destroy:function(){var n=this.classes;this.initialised=!1;this.elem.classList.remove(n.unpinned,n.pinned,n.top,n.notTop,n.initial);this.scroller.removeEventListener("scroll",this.debouncer,!1)},attachEvent:function(){this.initialised||(this.lastKnownScrollY=this.getScrollY(),this.initialised=!0,this.scroller.addEventListener("scroll",this.debouncer,!1),this.debouncer.handleEvent())},unpin:function(){var n=this.elem.classList,t=this.classes;!n.contains(t.pinned)&&n.contains(t.unpinned)||(n.add(t.unpinned),n.remove(t.pinned),this.onUnpin&&this.onUnpin.call(this))},pin:function(){var n=this.elem.classList,t=this.classes;n.contains(t.unpinned)&&(n.remove(t.unpinned),n.add(t.pinned),this.onPin&&this.onPin.call(this))},top:function(){var n=this.elem.classList,t=this.classes;n.contains(t.top)||(n.add(t.top),n.remove(t.notTop),this.onTop&&this.onTop.call(this))},notTop:function(){var n=this.elem.classList,t=this.classes;n.contains(t.notTop)||(n.add(t.notTop),n.remove(t.top),this.onNotTop&&this.onNotTop.call(this))},bottom:function(){var n=this.elem.classList,t=this.classes;n.contains(t.bottom)||(n.add(t.bottom),n.remove(t.notBottom),this.onBottom&&this.onBottom.call(this))},notBottom:function(){var n=this.elem.classList,t=this.classes;n.contains(t.notBottom)||(n.add(t.notBottom),n.remove(t.bottom),this.onNotBottom&&this.onNotBottom.call(this))},getScrollY:function(){return void 0!==this.scroller.pageYOffset?this.scroller.pageYOffset:void 0!==this.scroller.scrollTop?this.scroller.scrollTop:(document.documentElement||document.body.parentNode||document.body).scrollTop},getViewportHeight:function(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},getElementPhysicalHeight:function(n){return Math.max(n.offsetHeight,n.clientHeight)},getScrollerPhysicalHeight:function(){return this.scroller===window||this.scroller===document.body?this.getViewportHeight():this.getElementPhysicalHeight(this.scroller)},getDocumentHeight:function(){var n=document.body,t=document.documentElement;return Math.max(n.scrollHeight,t.scrollHeight,n.offsetHeight,t.offsetHeight,n.clientHeight,t.clientHeight)},getElementHeight:function(n){return Math.max(n.scrollHeight,n.offsetHeight,n.clientHeight)},getScrollerHeight:function(){return this.scroller===window||this.scroller===document.body?this.getDocumentHeight():this.getElementHeight(this.scroller)},isOutOfBounds:function(n){var t=0>n,i=n+this.getScrollerPhysicalHeight()>this.getScrollerHeight();return t||i},toleranceExceeded:function(n,t){return Math.abs(n-this.lastKnownScrollY)>=this.tolerance[t]},shouldUnpin:function(n,t){var i=n>this.lastKnownScrollY,r=n>=this.offset;return i&&r&&t},shouldPin:function(n,t){var i=n<this.lastKnownScrollY,r=n<=this.offset;return i&&t||r},update:function(){var n=this.getScrollY(),i=n>this.lastKnownScrollY?"down":"up",t=this.toleranceExceeded(n,i);this.isOutOfBounds(n)||(n<=this.offset?this.top():this.notTop(),n+this.getViewportHeight()>=this.getScrollerHeight()?this.bottom():this.notBottom(),this.shouldUnpin(n,t)?this.unpin():this.shouldPin(n,t)&&this.pin(),this.lastKnownScrollY=n)}},n.options={tolerance:{up:0,down:0},offset:200,scroller:window,classes:{pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",bottom:"headroom--bottom",notBottom:"headroom--not-bottom",initial:"headroom"}},n.cutsTheMustard="undefined"!=typeof t&&t.rAF&&t.bind&&t.classList,n}),function(n){n&&(n.fn.headroom=function(t){return this.each(function(){var r=n(this),i=r.data("headroom"),u=typeof t=="object"&&t;u=n.extend(!0,{},Headroom.options,u);i||(i=new Headroom(this,u),i.init(),r.data("headroom",i));typeof t=="string"&&(i[t](),t==="destroy"&&r.removeData("headroom"))})},n("[data-headroom]").each(function(){var t=n(this);t.headroom(t.data())}))}(window.Zepto||window.jQuery)