!function(){"use strict";var t=function(t,i){this.initDefaultOptions(),this.extendOptions(i),this.initMenuItems(t),this.getSectionsPositions(),this.bindWindowEvents(),this.bindMenuItems()};t.prototype.initDefaultOptions=function(){this.options={duration:400,activeOffset:40,scrollOffset:10,easingFunction:function(t,i,e,n){return(t/=n/2)<1?e/2*t*t*t+i:e/2*((t-=2)*t*t+2)+i}}},t.prototype.extendOptions=function(t){if(t)for(var i in this.options)this.options.hasOwnProperty(i)&&t[i]&&(this.options[i]=t[i])},t.prototype.initMenuItems=function(t){this.items=[],Array.isArray(t)===!1&&(t=[t]),t.forEach(function(t){var i=[].slice.call(document.querySelectorAll(t));this.items=this.items.concat(i)}.bind(this))},t.prototype.getTargetOffset=function(t){var i=t.getAttribute("href");return i.match(/^#?$/)?0:document.querySelector(i).offsetTop},t.prototype.bindWindowEvents=function(){window.addEventListener("scroll",this.onWindowUpdate.bind(this),!1),window.addEventListener("resize",this.onWindowUpdate.bind(this),!1)},t.prototype.bindMenuItems=function(){this.items.forEach(function(t){t.addEventListener("click",this.onMenuItemClick.bind(this),!1)}.bind(this))},t.prototype.onWindowUpdate=function(){this.getSectionsPositions(),this.updateActiveMenuItem()},t.prototype.getSectionsPositions=function(){this.positions=this.items.map(function(t){return this.getTargetOffset(t)-this.options.activeOffset}.bind(this))},t.prototype.updateActiveMenuItem=function(){if(this.getScrollOffset()+window.innerHeight===document.body.clientHeight)this.changeActiveMenuItem(this.items[this.items.length-1]);else{var t=this.items.filter(function(t,i){return this.positions[i]<=this.getScrollOffset()}.bind(this));t.length>0?this.changeActiveMenuItem(t[t.length-1]):this.resetActiveMenuItem()}},t.prototype.getScrollOffset=function(){return document.body.scrollTop||window.pageYOffset},t.prototype.resetActiveMenuItem=function(){this.items.forEach(function(t){t.classList.remove("active")})},t.prototype.changeActiveMenuItem=function(t){t.classList.contains("active")||(this.resetActiveMenuItem(),t.classList.add("active"))},t.prototype.onMenuItemClick=function(t){t.preventDefault();var i=this.items.indexOf(t.target);-1!==i&&(this.updateLocationHash(i),this.animatePageScroll(i))},t.prototype.updateLocationHash=function(t){var i=this.items[t].getAttribute("href"),e=location.pathname+location.search;i.match(/^#?$/)||(e+=i),history.pushState(i,document.title,e)},t.prototype.animatePageScroll=function(t){var i=-this.options.activeOffset+this.options.scrollOffset,e=this.positions[t]-i;this.scrollTo(e,this.options.duration)},t.prototype.scrollTo=function(t,i,e){if(!(0>=i)){var n=t-this.getScrollOffset();e=(e||0)+10,setTimeout(function(){var o=this.options.easingFunction(e,this.getScrollOffset(),n,i);window.scroll(0,o),i===e?this.updateActiveMenuItem():this.scrollTo(t,i,e)}.bind(this),10)}},window.ScrollMenu=t}();