/*global window */ (function(a,b){"use strict",b.fn.stickToTop=function(c){c=b.extend({scrollParent:window,offset:{top:0,left:0},bottomBound:0,onStick:null,onDetach:null},c,!0);var d=c.scrollParent,e="",f=b(d===window?d.document.body:d).offset();return b(this).each(function(){var g=this,h=b(g),i=h.position(),j=h.css("position"),k=h.width(),l=h.outerHeight(!0),m=!1,n=function(){var m=d.scrollTop||b(a).scrollTop(),n=(d==window?window.document.body:d).offsetHeight,o=c.bottomBound&&n-c.bottomBound-l,p=!!o&&o=i.top-c.offset.top+f.top,r=!q;q=q&&!p;if(p&&e!=="bottomBound"){var s=h.position();h.css({position:"absolute",top:o+"px",left:s.left+"px"}),e="bottomBound",c.onDetach&&c.onDetach.call(g);return}if(r&&e!=="initial"){var t={position:j};j!=="static"&&b.extend(t,{top:i.top+"px",left:i.left+"px"}),h.css(t),e="initial",c.onDetach&&c.onDetach.call(g);return}if(q&&e!=="fixed"){h.css({position:"fixed",top:f.top+(c.offset.top||0)+"px",left:f.left+i.left+(c.offset.left||0)+"px",width:k+"px"}),e="fixed",c.onStick&&c.onStick.call(g);return}},o=function(a){if(m)return;m=!0,window.setTimeout(function(){var a=h.css("position");i.left=h.css("position",j).position().left,h.css("position",a),e="",n(),m=!1},50)};b(window).on("resize",o),j==="relative"&&(j="static"),b(c.scrollParent).on("scroll",n),this.unstickToTop=function(){b(c.scrollParent).off("scroll",n),b(window).off("resize",o)}})}})(window.document,window.jQuery)