(function(n){typeof define=="function"&&define.amd?define(["jquery"],n):typeof module=="object"&&module.exports?module.exports=n(require("jquery")):n(jQuery)})(function(n){var e=Array.prototype.slice,h=Array.prototype.splice,u={topSpacing:0,bottomSpacing:0,className:"is-sticky",wrapperClassName:"sticky-wrapper",center:!1,getWidthFrom:"",widthFromWrapper:!0,responsiveWidth:!1,zIndex:"inherit"},f=n(window),c=n(document),i=[],o=f.height(),r=function(){for(var r,u,h,y,e=f.scrollTop(),l=c.height(),a=l-o,v=e>a?a-e:0,s=0,p=i.length;s<p;s++){var t=i[s],w=t.stickyWrapper.offset().top,b=w-t.topSpacing-v;t.stickyWrapper.css("height",t.stickyElement.outerHeight());e<=b?t.currentTop!==null&&(t.stickyElement.css({width:"",position:"",top:"","z-index":""}),t.stickyElement.parent().removeClass(t.className),t.stickyElement.trigger("sticky-end",[t]),t.currentTop=null):(r=l-t.stickyElement.outerHeight()-t.topSpacing-t.bottomSpacing-e-v,r=r<0?r+t.topSpacing:t.topSpacing,t.currentTop!==r&&(t.getWidthFrom?(padding=t.stickyElement.innerWidth()-t.stickyElement.width(),u=n(t.getWidthFrom).width()-padding||null):t.widthFromWrapper&&(u=t.stickyWrapper.width()),u==null&&(u=t.stickyElement.width()),t.stickyElement.css("width",u).css("position","fixed").css("top",r).css("z-index",t.zIndex),t.stickyElement.parent().addClass(t.className),t.currentTop===null?t.stickyElement.trigger("sticky-start",[t]):t.stickyElement.trigger("sticky-update",[t]),t.currentTop===t.topSpacing&&t.currentTop>r||t.currentTop===null&&r<t.topSpacing?t.stickyElement.trigger("sticky-bottom-reached",[t]):t.currentTop!==null&&r===t.topSpacing&&t.currentTop<r&&t.stickyElement.trigger("sticky-bottom-unreached",[t]),t.currentTop=r),h=t.stickyWrapper.parent(),y=t.stickyElement.offset().top+t.stickyElement.outerHeight()>=h.offset().top+h.outerHeight()&&t.stickyElement.offset().top<=t.topSpacing,y?t.stickyElement.css("position","absolute").css("top","").css("bottom",0).css("z-index",""):t.stickyElement.css("position","fixed").css("top",r).css("bottom","").css("z-index",t.zIndex))}},s=function(){var u,e,t,r;for(o=f.height(),u=0,e=i.length;u<e;u++)t=i[u],r=null,t.getWidthFrom?t.responsiveWidth&&(r=n(t.getWidthFrom).width()):t.widthFromWrapper&&(r=t.stickyWrapper.width()),r!=null&&t.stickyElement.css("width",r)},t={init:function(r){return this.each(function(){var e=n.extend({},u,r),f=n(this),s=f.attr("id"),h=s?s+"-"+u.wrapperClassName:u.wrapperClassName,c=n("<div><\/div>").attr("id",h).addClass(e.wrapperClassName),o;f.wrapAll(function(){if(n(this).parent("#"+h).length==0)return c});o=f.parent();e.center&&o.css({width:f.outerWidth(),marginLeft:"auto",marginRight:"auto"});f.css("float")==="right"&&f.css({float:"none"}).parent().css({float:"right"});e.stickyElement=f;e.stickyWrapper=o;e.currentTop=null;i.push(e);t.setWrapperHeight(this);t.setupChangeListeners(this)})},setWrapperHeight:function(t){var i=n(t),r=i.parent();r&&r.css("height",i.outerHeight())},setupChangeListeners:function(n){if(window.MutationObserver){var i=new window.MutationObserver(function(i){(i[0].addedNodes.length||i[0].removedNodes.length)&&t.setWrapperHeight(n)});i.observe(n,{subtree:!0,childList:!0})}else window.addEventListener?(n.addEventListener("DOMNodeInserted",function(){t.setWrapperHeight(n)},!1),n.addEventListener("DOMNodeRemoved",function(){t.setWrapperHeight(n)},!1)):window.attachEvent&&(n.attachEvent("onDOMNodeInserted",function(){t.setWrapperHeight(n)}),n.attachEvent("onDOMNodeRemoved",function(){t.setWrapperHeight(n)}))},update:r,unstick:function(){return this.each(function(){for(var r=this,u=n(r),f=-1,t=i.length;t-->0;)i[t].stickyElement.get(0)===r&&(h.call(i,t,1),f=t);f!==-1&&(u.unwrap(),u.css({width:"",position:"",top:"",float:"","z-index":""}))})}};window.addEventListener?(window.addEventListener("scroll",r,!1),window.addEventListener("resize",s,!1)):window.attachEvent&&(window.attachEvent("onscroll",r),window.attachEvent("onresize",s));n.fn.sticky=function(i){if(t[i])return t[i].apply(this,e.call(arguments,1));if(typeof i!="object"&&i)n.error("Method "+i+" does not exist on jQuery.sticky");else return t.init.apply(this,arguments)};n.fn.unstick=function(i){if(t[i])return t[i].apply(this,e.call(arguments,1));if(typeof i!="object"&&i)n.error("Method "+i+" does not exist on jQuery.sticky");else return t.unstick.apply(this,arguments)};n(function(){setTimeout(r,0)})});!function(n,t,i,r){function f(t,i){this.element=t;this.options=n.extend({},h,i);this._defaults=h;this._name=u;this.init()}var u="stellar",h={scrollProperty:"scroll",positionProperty:"position",horizontalScrolling:!0,verticalScrolling:!0,horizontalOffset:0,verticalOffset:0,responsive:!1,parallaxBackgrounds:!0,parallaxElements:!0,hideDistantElements:!0,hideElement:function(n){n.hide()},showElement:function(n){n.show()}},e={scroll:{getLeft:function(n){return n.scrollLeft()},setLeft:function(n,t){n.scrollLeft(t)},getTop:function(n){return n.scrollTop()},setTop:function(n,t){n.scrollTop(t)}},position:{getLeft:function(n){return-1*parseInt(n.css("left"),10)},getTop:function(n){return-1*parseInt(n.css("top"),10)}},margin:{getLeft:function(n){return-1*parseInt(n.css("margin-left"),10)},getTop:function(n){return-1*parseInt(n.css("margin-top"),10)}},transform:{getLeft:function(n){var t=getComputedStyle(n[0])[o];return"none"!==t?-1*parseInt(t.match(/(-?[0-9]+)/g)[4],10):0},getTop:function(n){var t=getComputedStyle(n[0])[o];return"none"!==t?-1*parseInt(t.match(/(-?[0-9]+)/g)[5],10):0}}},c={position:{setLeft:function(n,t){n.css("left",t)},setTop:function(n,t){n.css("top",t)}},transform:{setPosition:function(n,t,i,r,u){n[0].style[o]="translate3d("+(t-i)+"px, "+(r-u)+"px, 0)"}}},v=function(){var i,u=/^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/,r=n("script")[0].style,t="";for(i in r)if(u.test(i)){t=i.match(u)[0];break}return"WebkitOpacity"in r&&(t="Webkit"),"KhtmlOpacity"in r&&(t="Khtml"),function(n){return t+(t.length>0?n.charAt(0).toUpperCase()+n.slice(1):n)}}(),o=v("transform"),l=n("<div />",{style:"background:#fff"}).css("background-position-x")!==r,s=l?function(n,t,i){n.css({"background-position-x":t,"background-position-y":i})}:function(n,t,i){n.css("background-position",t+" "+i)},y=l?function(n){return[n.css("background-position-x"),n.css("background-position-y")]}:function(n){return n.css("background-position").split(" ")},a=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(n){setTimeout(n,1e3/60)};f.prototype={init:function(){this.options.name=u+"_"+Math.floor(1e9*Math.random());this._defineElements();this._defineGetters();this._defineSetters();this._handleWindowLoadAndResize();this._detectViewport();this.refresh({firstLoad:!0});"scroll"===this.options.scrollProperty?this._handleScrollEvent():this._startAnimationLoop()},_defineElements:function(){this.element===i.body&&(this.element=t);this.$scrollElement=n(this.element);this.$element=this.element===t?n("body"):this.$scrollElement;this.$viewportElement=this.options.viewportElement!==r?n(this.options.viewportElement):this.$scrollElement[0]===t||"scroll"===this.options.scrollProperty?this.$scrollElement:this.$scrollElement.parent()},_defineGetters:function(){var n=this,t=e[n.options.scrollProperty];this._getScrollLeft=function(){return t.getLeft(n.$scrollElement)};this._getScrollTop=function(){return t.getTop(n.$scrollElement)}},_defineSetters:function(){var t=this,r=e[t.options.scrollProperty],i=c[t.options.positionProperty],u=r.setLeft,f=r.setTop;this._setScrollLeft="function"==typeof u?function(n){u(t.$scrollElement,n)}:n.noop;this._setScrollTop="function"==typeof f?function(n){f(t.$scrollElement,n)}:n.noop;this._setPosition=i.setPosition||function(n,r,u,f,e){t.options.horizontalScrolling&&i.setLeft(n,r,u);t.options.verticalScrolling&&i.setTop(n,f,e)}},_handleWindowLoadAndResize:function(){var i=this,r=n(t);i.options.responsive&&r.bind("load."+this.name,function(){i.refresh()});r.bind("resize."+this.name,function(){i._detectViewport();i.options.responsive&&i.refresh()})},refresh:function(i){var r=this,u=r._getScrollLeft(),f=r._getScrollTop();i&&i.firstLoad||this._reset();this._setScrollLeft(0);this._setScrollTop(0);this._setOffsets();this._findParticles();this._findBackgrounds();i&&i.firstLoad&&/WebKit/.test(navigator.userAgent)&&n(t).load(function(){var n=r._getScrollLeft(),t=r._getScrollTop();r._setScrollLeft(n+1);r._setScrollTop(t+1);r._setScrollLeft(n);r._setScrollTop(t)});this._setScrollLeft(u);this._setScrollTop(f)},_detectViewport:function(){var n=this.$viewportElement.offset(),t=null!==n&&n!==r;this.viewportWidth=this.$viewportElement.width();this.viewportHeight=this.$viewportElement.height();this.viewportOffsetTop=t?n.top:0;this.viewportOffsetLeft=t?n.left:0},_findParticles:function(){var t=this,i;if(this._getScrollLeft(),this._getScrollTop(),this.particles!==r)for(i=this.particles.length-1;i>=0;i--)this.particles[i].$element.data("stellar-elementIsActive",r);this.particles=[];this.options.parallaxElements&&this.$element.find("[data-stellar-ratio]").each(function(){var f,e,o,s,h,c,u,l,a,i=n(this),v=0,y=0,p=0,w=0;if(i.data("stellar-elementIsActive")){if(i.data("stellar-elementIsActive")!==this)return}else i.data("stellar-elementIsActive",this);t.options.showElement(i);i.data("stellar-startingLeft")?(i.css("left",i.data("stellar-startingLeft")),i.css("top",i.data("stellar-startingTop"))):(i.data("stellar-startingLeft",i.css("left")),i.data("stellar-startingTop",i.css("top")));o=i.position().left;s=i.position().top;h="auto"===i.css("margin-left")?0:parseInt(i.css("margin-left"),10);c="auto"===i.css("margin-top")?0:parseInt(i.css("margin-top"),10);l=i.offset().left-h;a=i.offset().top-c;i.parents().each(function(){var t=n(this);return t.data("stellar-offset-parent")===!0?(v=p,y=w,u=t,!1):(p+=t.position().left,void(w+=t.position().top))});f=i.data("stellar-horizontal-offset")!==r?i.data("stellar-horizontal-offset"):u!==r&&u.data("stellar-horizontal-offset")!==r?u.data("stellar-horizontal-offset"):t.horizontalOffset;e=i.data("stellar-vertical-offset")!==r?i.data("stellar-vertical-offset"):u!==r&&u.data("stellar-vertical-offset")!==r?u.data("stellar-vertical-offset"):t.verticalOffset;t.particles.push({$element:i,$offsetParent:u,isFixed:"fixed"===i.css("position"),horizontalOffset:f,verticalOffset:e,startingPositionLeft:o,startingPositionTop:s,startingOffsetLeft:l,startingOffsetTop:a,parentOffsetLeft:v,parentOffsetTop:y,stellarRatio:i.data("stellar-ratio")!==r?i.data("stellar-ratio"):1,width:i.outerWidth(!0),height:i.outerHeight(!0),isHidden:!1})})},_findBackgrounds:function(){var t,i=this,u=this._getScrollLeft(),f=this._getScrollTop();this.backgrounds=[];this.options.parallaxBackgrounds&&(t=this.$element.find("[data-stellar-background-ratio]"),this.$element.data("stellar-background-ratio")&&(t=t.add(this.$element)),t.each(function(){var h,c,l,a,v,p,e,t=n(this),o=y(t),w=0,b=0,k=0,d=0;if(t.data("stellar-backgroundIsActive")){if(t.data("stellar-backgroundIsActive")!==this)return}else t.data("stellar-backgroundIsActive",this);t.data("stellar-backgroundStartingLeft")?s(t,t.data("stellar-backgroundStartingLeft"),t.data("stellar-backgroundStartingTop")):(t.data("stellar-backgroundStartingLeft",o[0]),t.data("stellar-backgroundStartingTop",o[1]));l="auto"===t.css("margin-left")?0:parseInt(t.css("margin-left"),10);a="auto"===t.css("margin-top")?0:parseInt(t.css("margin-top"),10);v=t.offset().left-l-u;p=t.offset().top-a-f;t.parents().each(function(){var t=n(this);return t.data("stellar-offset-parent")===!0?(w=k,b=d,e=t,!1):(k+=t.position().left,void(d+=t.position().top))});h=t.data("stellar-horizontal-offset")!==r?t.data("stellar-horizontal-offset"):e!==r&&e.data("stellar-horizontal-offset")!==r?e.data("stellar-horizontal-offset"):i.horizontalOffset;c=t.data("stellar-vertical-offset")!==r?t.data("stellar-vertical-offset"):e!==r&&e.data("stellar-vertical-offset")!==r?e.data("stellar-vertical-offset"):i.verticalOffset;i.backgrounds.push({$element:t,$offsetParent:e,isFixed:"fixed"===t.css("background-attachment"),horizontalOffset:h,verticalOffset:c,startingValueLeft:o[0],startingValueTop:o[1],startingBackgroundPositionLeft:isNaN(parseInt(o[0],10))?0:parseInt(o[0],10),startingBackgroundPositionTop:isNaN(parseInt(o[1],10))?0:parseInt(o[1],10),startingPositionLeft:t.position().left,startingPositionTop:t.position().top,startingOffsetLeft:v,startingOffsetTop:p,parentOffsetLeft:w,parentOffsetTop:b,stellarRatio:t.data("stellar-background-ratio")===r?1:t.data("stellar-background-ratio")})}))},_reset:function(){for(var t,r,u,i,n=this.particles.length-1;n>=0;n--)t=this.particles[n],r=t.$element.data("stellar-startingLeft"),u=t.$element.data("stellar-startingTop"),this._setPosition(t.$element,r,r,u,u),this.options.showElement(t.$element),t.$element.data("stellar-startingLeft",null).data("stellar-elementIsActive",null).data("stellar-backgroundIsActive",null);for(n=this.backgrounds.length-1;n>=0;n--)i=this.backgrounds[n],i.$element.data("stellar-backgroundStartingLeft",null).data("stellar-backgroundStartingTop",null),s(i.$element,i.startingValueLeft,i.startingValueTop)},destroy:function(){this._reset();this.$scrollElement.unbind("resize."+this.name).unbind("scroll."+this.name);this._animationLoop=n.noop;n(t).unbind("load."+this.name).unbind("resize."+this.name)},_setOffsets:function(){var i=this,r=n(t);r.unbind("resize.horizontal-"+this.name).unbind("resize.vertical-"+this.name);"function"==typeof this.options.horizontalOffset?(this.horizontalOffset=this.options.horizontalOffset(),r.bind("resize.horizontal-"+this.name,function(){i.horizontalOffset=i.options.horizontalOffset()})):this.horizontalOffset=this.options.horizontalOffset;"function"==typeof this.options.verticalOffset?(this.verticalOffset=this.options.verticalOffset(),r.bind("resize.vertical-"+this.name,function(){i.verticalOffset=i.options.verticalOffset()})):this.verticalOffset=this.options.verticalOffset},_repositionElements:function(){var n,r,t,l,a,e,o,h,c,i,u=this._getScrollLeft(),f=this._getScrollTop(),v=!0,y=!0;if(this.currentScrollLeft!==u||this.currentScrollTop!==f||this.currentWidth!==this.viewportWidth||this.currentHeight!==this.viewportHeight){for(this.currentScrollLeft=u,this.currentScrollTop=f,this.currentWidth=this.viewportWidth,this.currentHeight=this.viewportHeight,i=this.particles.length-1;i>=0;i--)n=this.particles[i],r=n.isFixed?1:0,this.options.horizontalScrolling?(e=(u+n.horizontalOffset+this.viewportOffsetLeft+n.startingPositionLeft-n.startingOffsetLeft+n.parentOffsetLeft)*-(n.stellarRatio+r-1)+n.startingPositionLeft,h=e-n.startingPositionLeft+n.startingOffsetLeft):(e=n.startingPositionLeft,h=n.startingOffsetLeft),this.options.verticalScrolling?(o=(f+n.verticalOffset+this.viewportOffsetTop+n.startingPositionTop-n.startingOffsetTop+n.parentOffsetTop)*-(n.stellarRatio+r-1)+n.startingPositionTop,c=o-n.startingPositionTop+n.startingOffsetTop):(o=n.startingPositionTop,c=n.startingOffsetTop),this.options.hideDistantElements&&(y=!this.options.horizontalScrolling||h+n.width>(n.isFixed?0:u)&&h<(n.isFixed?0:u)+this.viewportWidth+this.viewportOffsetLeft,v=!this.options.verticalScrolling||c+n.height>(n.isFixed?0:f)&&c<(n.isFixed?0:f)+this.viewportHeight+this.viewportOffsetTop),y&&v?(n.isHidden&&(this.options.showElement(n.$element),n.isHidden=!1),this._setPosition(n.$element,e,n.startingPositionLeft,o,n.startingPositionTop)):n.isHidden||(this.options.hideElement(n.$element),n.isHidden=!0);for(i=this.backgrounds.length-1;i>=0;i--)t=this.backgrounds[i],r=t.isFixed?0:1,l=this.options.horizontalScrolling?(u+t.horizontalOffset-this.viewportOffsetLeft-t.startingOffsetLeft+t.parentOffsetLeft-t.startingBackgroundPositionLeft)*(r-t.stellarRatio)+"px":t.startingValueLeft,a=this.options.verticalScrolling?(f+t.verticalOffset-this.viewportOffsetTop-t.startingOffsetTop+t.parentOffsetTop-t.startingBackgroundPositionTop)*(r-t.stellarRatio)+"px":t.startingValueTop,s(t.$element,l,a)}},_handleScrollEvent:function(){var i=this,n=!1,r=function(){i._repositionElements();n=!1},t=function(){n||(a(r),n=!0)};this.$scrollElement.bind("scroll."+this.name,t);t()},_startAnimationLoop:function(){var n=this;this._animationLoop=function(){a(n._animationLoop);n._repositionElements()};this._animationLoop()}};n.fn[u]=function(t){var i=arguments;return t===r||"object"==typeof t?this.each(function(){n.data(this,"plugin_"+u)||n.data(this,"plugin_"+u,new f(this,t))}):"string"==typeof t&&"_"!==t[0]&&"init"!==t?this.each(function(){var r=n.data(this,"plugin_"+u);r instanceof f&&"function"==typeof r[t]&&r[t].apply(r,Array.prototype.slice.call(i,1));"destroy"===t&&n.data(this,"plugin_"+u,null)}):void 0};n[u]=function(){var i=n(t);return i.stellar.apply(i,Array.prototype.slice.call(arguments,0))};n[u].scrollProperty=e;n[u].positionProperty=c;t.Stellar=f}(jQuery,this,document)