define(["dom","layoutManager","browser","css!./headroom"],function(dom,layoutManager,browser){"use strict";function Debouncer(callback){this.callback=callback,this.ticking=!1}function Headroom(elems,options){options=Object.assign(Headroom.options,options||{}),this.lastKnownScrollY=0,this.elems=elems,this.debouncer=new Debouncer(this.update.bind(this)),this.offset=options.offset,this.scroller=options.scroller,this.initialised=!1,this.initialClass=options.initialClass,this.unPinnedClass=options.unPinnedClass,this.upTolerance=options.upTolerance,this.downTolerance=options.downTolerance}var requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame;return Debouncer.prototype={constructor:Debouncer,update:function(){this.callback&&this.callback(),this.ticking=!1},handleEvent:function(){this.ticking||(requestAnimationFrame(this.rafCallback||(this.rafCallback=this.update.bind(this))),this.ticking=!0)}},Headroom.prototype={constructor:Headroom,init:function(){if(browser.supportsCssAnimation()&&!browser.firefox){for(var i=0,length=this.elems.length;i=this[direction+"Tolerance"]},shouldUnpin:function(currentScrollY,toleranceExceeded){var scrollingDown=currentScrollY>this.lastKnownScrollY,pastOffset=currentScrollY>=this.offset;return scrollingDown&&pastOffset&&toleranceExceeded},shouldPin:function(currentScrollY,toleranceExceeded){var scrollingUp=currentScrollYthis.lastKnownScrollY?"down":"up",toleranceExceeded=this.toleranceExceeded(currentScrollY,scrollDirection);currentScrollY<0||(this.shouldUnpin(currentScrollY,toleranceExceeded)?this.unpin():this.shouldPin(currentScrollY,toleranceExceeded)?this.pin(currentScrollY):this.clear(),this.lastKnownScrollY=currentScrollY)}},Headroom.options={upTolerance:0,downTolerance:0,offset:0,scroller:window,initialClass:"headroom",unPinnedClass:"headroom--unpinned"},Headroom});