/*!
 * jQuery Scrollify
 * Version 1.0.21
 *
 * Requires:
 * - jQuery 1.7 or higher
 *
 * https://github.com/lukehaas/Scrollify
 *
 * Copyright 2016, Luke Haas
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if touchScroll is false - update index
 */
(function(n,t){"use strict";typeof define=="function"&&define.amd?define(["jquery"],function(i){return t(i,n,n.document)}):typeof module=="object"&&module.exports?module.exports=t(require("jquery"),n,n.document):t(jQuery,n,n.document)})(typeof window!="undefined"?window:this,function(n,t,i,r){"use strict";function et(){return t.innerHeight+u.offset}function a(i,r,f,e){if(ot===i&&(f=!1),w===!0)return!0;if(v[i]){if(ut=!1,tt===!0&&(tt=!1,u.afterRender()),f&&typeof u.before=="function"&&u.before(i,y)===!1)return!0;if(b=1,ft=i?o[i]:0,tt===!1&&ot>i&&e===!1&&p[i]&&(l=et(),b=parseInt(y[i].outerHeight()/l),ft=parseInt(o[i])+(y[i].outerHeight()-l)),u.updateHash&&u.sectionName&&!(tt===!0&&i===0))if(history.pushState)try{history.replaceState(null,null,v[i])}catch(s){t.console&&console.warn("Scrollify warning: Page must be hosted to manipulate the hash value.")}else t.location.hash=v[i];if(ot=i,r)n(u.target).stop().scrollTop(ft),f&&u.after(i,y);else{if(g=!0,n().velocity?n(u.target).stop().velocity("scroll",{duration:u.scrollSpeed,easing:u.easing,offset:ft,mobileHA:!1}):n(u.target).stop().animate({scrollTop:ft},u.scrollSpeed,u.easing),t.location.hash.length&&u.sectionName&&t.console)try{n(t.location.hash).length&&console.warn("Scrollify warning: ID matches hash value - this will cause the page to anchor.")}catch(s){}n(u.target).promise().done(function(){g=!1;tt=!1;f&&u.after(i,y)})}}}function yt(n){function t(t){for(var r=0,u=n.slice(Math.max(n.length-t,1)),i=0;i<u.length;i++)r+=u[i];return Math.ceil(r/t)}var i=t(10),r=t(70);return i>=r?!0:!1}function pt(n,t){for(var i=v.length;i>=0;i--)typeof n=="string"?v[i]===n&&(f=i,a(i,t,!0,!0)):i===n&&(f=i,a(i,t,!0,!0))}var o=[],v=[],y=[],p=[],f=0,ot=0,b=1,ct=!1,st,lt,s=n(t),l,k=s.scrollTop(),ut=!1,g=!1,ht=!1,h,e,d,w=!1,nt=[],at=(new Date).getTime(),tt=!0,it=!1,ft=0,vt="onwheel"in i?"wheel":i.onmousewheel!==r?"mousewheel":"DOMMouseScroll",rt={passive:!1},u={section:".section",sectionName:"section-name",interstitialSection:"",easing:"easeOutExpo",scrollSpeed:1100,offset:0,scrollbars:!0,target:"html,body",standardScrollElements:!1,setHeights:!0,overflowScroll:!0,updateHash:!0,touchScroll:!0,before:function(){},after:function(){},afterResize:function(){},afterRender:function(){}},c=function(r){function c(t){n().velocity?n(u.target).stop().velocity("scroll",{duration:u.scrollSpeed,easing:u.easing,offset:t,mobileHA:!1}):n(u.target).stop().animate({scrollTop:t},u.scrollSpeed,u.easing)}function ot(t){t&&(k=s.scrollTop());var i=u.section;p=[];u.interstitialSection.length&&(i+=","+u.interstitialSection);u.scrollbars===!1&&(u.overflowScroll=!1);l=et();n(i).each(function(t){var i=n(this);u.setHeights?i.is(u.interstitialSection)?p[t]=!1:i.css("height","auto").outerHeight()<l||i.css("overflow")==="hidden"?(i.css({height:l}),p[t]=!1):(i.css({height:i.outerHeight()}),p[t]=u.overflowScroll?!0:!1):p[t]=i.outerHeight()<l||u.overflowScroll===!1?!1:!0});t&&s.scrollTop(k)}function pt(i){var r=u.section;u.interstitialSection.length&&(r+=","+u.interstitialSection);o=[];v=[];y=[];n(r).each(function(i){var e=n(this);o[i]=i>0?parseInt(e.offset().top)+u.offset:parseInt(e.offset().top);u.sectionName&&e.data(u.sectionName)?v[i]="#"+e.data(u.sectionName).toString().replace(/ /g,"-"):e.is(u.interstitialSection)===!1?v[i]="#"+(i+1):(v[i]="#",i===n(r).length-1&&i>1&&(o[i]=o[i-1]+(parseInt(n(n(r)[i-1]).outerHeight())-parseInt(n(t).height()))+parseInt(e.outerHeight())));y[i]=e;try{n(v[i]).length&&t.console&&console.warn("Scrollify warning: Section names can't match IDs - this will cause the browser to anchor.")}catch(s){}t.location.hash===v[i]&&(f=i,ct=!0)});!0===i&&a(f,!1,!1,!1)}function tt(){return p[f]?(k=s.scrollTop(),k>parseInt(o[f])?!1:!0):!0}function ft(){return p[f]?(k=s.scrollTop(),l=et(),k<parseInt(o[f])+(y[f].outerHeight()-l)-28?!1:!0):!0}if(it=!0,n.easing.easeOutExpo=function(n,t,i,r,u){return t==u?i+r:r*(-Math.pow(2,-10*t/u)+1)+i},h={handleMousedown:function(){if(w===!0)return!0;ut=!1;ht=!1},handleMouseup:function(){if(w===!0)return!0;ut=!0;ht&&h.calculateNearest(!1,!0)},handleScroll:function(){if(w===!0)return!0;st&&clearTimeout(st);st=setTimeout(function(){if(ht=!0,ut===!1)return!1;ut=!1;h.calculateNearest(!1,!0)},200)},calculateNearest:function(n,t){k=s.scrollTop();for(var i=1,h=o.length,r=0,e=Math.abs(o[0]-k),u;i<h;i++)u=Math.abs(o[i]-k),u<e&&(e=u,r=i);(ft()&&r>f||tt())&&(f=r,a(r,n,t,!1))},wheelHandler:function(i){var r,e,s;if(w===!0||u.standardScrollElements&&(n(i.target).is(u.standardScrollElements)||n(i.target).closest(u.standardScrollElements).length))return!0;if(p[f]||i.preventDefault(),r=(new Date).getTime(),i=i||t.event,e=i.originalEvent?i.originalEvent.wheelDelta||-i.originalEvent.deltaY||-i.originalEvent.detail:i.wheelDelta||-i.deltaY||-i.detail,s=Math.max(-1,Math.min(1,e)),nt.length>149&&nt.shift(),nt.push(Math.abs(e)),r-at>200&&(nt=[]),at=r,g)return!1;if(s<0){if(f<o.length-1&&ft())if(yt(nt))i.preventDefault(),f++,g=!0,a(f,!1,!0,!1);else return!1}else if(s>0&&f>0&&tt())if(yt(nt))i.preventDefault(),f--,g=!0,a(f,!1,!0,!1);else return!1},keyHandler:function(t){if(w===!0||i.activeElement.readOnly===!1||u.standardScrollElements&&(n(t.target).is(u.standardScrollElements)||n(t.target).closest(u.standardScrollElements).length))return!0;if(g===!0)return!1;t.keyCode==38||t.keyCode==33?f>0&&tt()&&(t.preventDefault(),f--,a(f,!1,!0,!1)):(t.keyCode==40||t.keyCode==34)&&f<o.length-1&&ft()&&(t.preventDefault(),f++,a(f,!1,!0,!1))},init:function(){if(u.scrollbars){s.on("mousedown",h.handleMousedown);s.on("mouseup",h.handleMouseup);s.on("scroll",h.handleScroll)}else n("body").css({overflow:"hidden"});t.addEventListener(vt,h.wheelHandler,{passive:!1});s.on("keydown",h.keyHandler)}},e={touches:{touchstart:{y:-1,x:-1},touchmove:{y:-1,x:-1},touchend:!1,direction:"undetermined"},options:{distance:30,timeGap:800,timeStamp:(new Date).getTime()},touchHandler:function(t){if(w===!0||u.standardScrollElements&&(n(t.target).is(u.standardScrollElements)||n(t.target).closest(u.standardScrollElements).length))return!0;var i;if(typeof t!="undefined"&&typeof t.touches!="undefined"){i=t.touches[0];switch(t.type){case"touchstart":e.touches.touchstart.y=i.pageY;e.touches.touchmove.y=-1;e.touches.touchstart.x=i.pageX;e.touches.touchmove.x=-1;e.options.timeStamp=(new Date).getTime();e.touches.touchend=!1;case"touchmove":e.touches.touchmove.y=i.pageY;e.touches.touchmove.x=i.pageX;e.touches.touchstart.y!==e.touches.touchmove.y&&Math.abs(e.touches.touchstart.y-e.touches.touchmove.y)>Math.abs(e.touches.touchstart.x-e.touches.touchmove.x)&&(t.preventDefault(),e.touches.direction="y",e.options.timeStamp+e.options.timeGap<(new Date).getTime()&&e.touches.touchend==!1&&(e.touches.touchend=!0,e.touches.touchstart.y>-1&&Math.abs(e.touches.touchmove.y-e.touches.touchstart.y)>e.options.distance&&(e.touches.touchstart.y<e.touches.touchmove.y?e.up():e.down())));break;case"touchend":e.touches[t.type]===!1&&(e.touches[t.type]=!0,e.touches.touchstart.y>-1&&e.touches.touchmove.y>-1&&e.touches.direction==="y"&&(Math.abs(e.touches.touchmove.y-e.touches.touchstart.y)>e.options.distance&&(e.touches.touchstart.y<e.touches.touchmove.y?e.up():e.down()),e.touches.touchstart.y=-1,e.touches.touchstart.x=-1,e.touches.direction="undetermined"))}}},down:function(){f<o.length&&(ft()&&f<o.length-1?(f++,a(f,!1,!0,!1)):(l=et(),Math.floor(y[f].height()/l)>b?(c(parseInt(o[f])+l*b),b+=1):c(parseInt(o[f])+(y[f].outerHeight()-l))))},up:function(){f>=0&&(tt()&&f>0?(f--,a(f,!1,!0,!1)):b>2?(l=et(),b-=1,c(parseInt(o[f])+l*b)):(b=1,c(parseInt(o[f]))))},init:function(){i.addEventListener&&u.touchScroll&&(i.addEventListener("touchstart",e.touchHandler,rt),i.addEventListener("touchmove",e.touchHandler,rt),i.addEventListener("touchend",e.touchHandler,rt))}},d={refresh:function(n,t){clearTimeout(lt);lt=setTimeout(function(){ot(!0);pt(t,!1);n&&u.afterResize()},400)},handleUpdate:function(){d.refresh(!1,!1)},handleResize:function(){d.refresh(!0,!1)},handleOrientation:function(){d.refresh(!0,!0)}},u=n.extend(u,r),ot(!1),pt(!1,!0),!0===ct?a(f,!1,!0,!0):setTimeout(function(){h.calculateNearest(!0,!1)},200),o.length){h.init();e.init();s.on("resize",d.handleResize);i.addEventListener&&t.addEventListener("orientationchange",d.handleOrientation,!1)}};return c.move=function(t){if(t===r)return!1;typeof t!="number"&&t.originalEvent&&(t=n(this).attr("href"));pt(t,!1)},c.instantMove=function(n){if(n===r)return!1;pt(n,!0)},c.next=function(){f<v.length&&(f+=1,a(f,!1,!0,!0))},c.previous=function(){f>0&&(f-=1,a(f,!1,!0,!0))},c.instantNext=function(){f<v.length&&(f+=1,a(f,!0,!0,!0))},c.instantPrevious=function(){f>0&&(f-=1,a(f,!0,!0,!0))},c.destroy=function(){if(!it)return!1;u.setHeights&&n(u.section).each(function(){n(this).css("height","auto")});s.off("resize",d.handleResize);u.scrollbars&&(s.off("mousedown",h.handleMousedown),s.off("mouseup",h.handleMouseup),s.off("scroll",h.handleScroll));t.removeEventListener(vt,h.wheelHandler);s.off("keydown",h.keyHandler);i.addEventListener&&u.touchScroll&&(i.removeEventListener("touchstart",e.touchHandler,rt),i.removeEventListener("touchmove",e.touchHandler,rt),i.removeEventListener("touchend",e.touchHandler,rt));o=[];v=[];y=[];p=[];tt=!0;it=!1},c.update=function(){if(!it)return!1;d.handleUpdate()},c.current=function(){return y[f]},c.currentIndex=function(){return f},c.disable=function(){w=!0},c.enable=function(){w=!1;it&&h.calculateNearest(!1,!1)},c.isDisabled=function(){return w},c.setOptions=function(i){if(!it)return!1;typeof i=="object"?(u=n.extend(u,i),d.handleUpdate()):t.console&&console.warn("Scrollify warning: setOptions expects an object.")},n.scrollify=c,c})