'),n.push({id:e,text:l})})}e.push({id:o,text:r,sub_sections:n})}),i.sections.data=e},_tear_down_sections:function(t){s(t).each(function(){var t=this.sub_sections;s("#"+this.id).children().unwrap(),t.length>0&&s(t).each(function(){s("#"+this.id).children().unwrap()})})},_setup_nav:function(t){var e=s("",{"class":i.settings.className+"__heading",text:i.settings.headlineText}),n=s("",{"class":i.settings.className+"__wrapper"}),a=s("",{"class":i.settings.className,role:"navigation"}),o=s("",{"class":i.settings.className+"__list"});s.each(t,function(t){var e,n=0===t?s("",{"class":i.settings.className+"__item active"}):s("",{"class":i.settings.className+"__item"}),a=s("",{href:"#"+this.id,"class":i.settings.className+"__link",text:this.text});this.sub_sections.length>0&&(n.addClass("is-parent-item"),e=s("",{"class":i.settings.className+"__sub-list"}),s.each(this.sub_sections,function(){var t=s("",{"class":i.settings.className+"__sub-item"}),n=s("",{href:"#"+this.id,"class":i.settings.className+"__sub-link",text:this.text});e.append(t.append(n))})),o.append(n.append(a).append(e))}),i.settings.showHeadline?a.append(n.append(e).append(o)):a.append(n.append(o)),i.nav=a},_insert_nav:function(){var s=i.settings.insertLocation,t=i.settings.insertTarget;i.nav[s](t)},_setup_pos:function(){var t=i.nav,e=s(window).height(),n=t.offset().top;s.each(i.sections.data,function(){var t=s("#"+this.id),e=t.height();this.top_offset=t.offset().top,this.bottom_offset=this.top_offset+e}),i.dims={vp_height:e,nav_offset:n}},_check_pos:function(){var t=i.nav,e=s(window).scrollTop(),n=e+i.settings.scrollOffset,a=e+i.dims.vp_height-i.settings.scrollOffset,o=[];e>i.dims.nav_offset-i.settings.fixedMargin?t.addClass("fixed"):t.removeClass("fixed"),s.each(i.sections.data,function(){(this.top_offset>n&&a>this.top_offset||this.bottom_offset>n&&a>this.bottom_offset||n>this.top_offset&&this.bottom_offset>a)&&o.push(this)}),t.find("."+i.settings.className+"__item").removeClass("active").removeClass("in-view"),s.each(o,function(s){0===s?t.find('a[href="#'+this.id+'"]').parents("."+i.settings.className+"__item").addClass("active").addClass("in-view"):t.find('a[href="#'+this.id+'"]').parents("."+i.settings.className+"__item").addClass("in-view"),s++,i.sections.active=o})},_init_scroll_listener:function(){s(window).on("scroll.scrollNav",function(){i._check_pos()})},_rm_scroll_listeners:function(){s(window).off("scroll.scrollNav")},_init_resize_listener:function(){s(window).on("resize.scrollNav",function(){i._setup_pos(),i._check_pos()})},_rm_resize_listener:function(){s(window).off("resize.scrollNav")},_init_click_listener:function(){s("."+i.settings.className).find("a").on("click.scrollNav",function(e){e.preventDefault();var n=s(this).attr("href"),a=i.settings.speed,o=i.settings.scrollOffset,l=i.settings.animated;t(n,a,o,l)})},_rm_click_listener:function(){s("."+i.settings.className).find("a").off("click.scrollNav")},_init_keyboard_listener:function(e){i.settings.arrowKeys&&s(document).on("keydown.scrollNav",function(s){if(40===s.keyCode||38===s.keyCode){var n=function(s){var t=0,n=e.length;for(t;n>t;t++)if(e[t].id===i.sections.active[0].id){var a=40===s?t+1:t-1,o=void 0===e[a]?void 0:e[a].id;return o}},a=n(s.keyCode);if(void 0!==a){s.preventDefault();var o="#"+a,l=i.settings.speed,c=i.settings.scrollOffset,r=i.settings.animated;t(o,l,c,r)}}})},_rm_keyboard_listener:function(){s(document).off("keydown.scrollNav")},init:function(n){return this.each(function(){var a=s(this);i.settings=s.extend({},i.defaults,n),i.settings.insertTarget=i.settings.insertTarget?s(i.settings.insertTarget):a,a.length>0?(i.settings.onInit&&i.settings.onInit.call(this),i._set_body_class("loading"),i._find_sections(a),a.find(i.settings.sections).length>0?(i._setup_sections(i.sections.raw),i._setup_nav(i.sections.data),i.settings.insertTarget.length>0?(i._insert_nav(),i._setup_pos(),i._check_pos(),i._init_scroll_listener(),i._init_resize_listener(),i._init_click_listener(),i._init_keyboard_listener(i.sections.data),i._set_body_class("success"),t(e()),i.settings.onRender&&i.settings.onRender.call(this)):(console.log('Build failed, scrollNav could not find "'+i.settings.insertTarget+'"'),i._set_body_class("failed"))):(console.log('Build failed, scrollNav could not find any "'+i.settings.sections+'s" inside of "'+a.selector+'"'),i._set_body_class("failed"))):(console.log('Build failed, scrollNav could not find "'+a.selector+'"'),i._set_body_class("failed"))})},destroy:function(){return this.each(function(){i._rm_scroll_listeners(),i._rm_resize_listener(),i._rm_click_listener(),i._rm_keyboard_listener(),s("body").removeClass("sn-loading sn-active sn-failed"),s("."+i.settings.className).remove(),i._tear_down_sections(i.sections.data),i.settings.onDestroy&&i.settings.onDestroy.call(this),i.settings=[],i.sections=void 0})}};s.fn.scrollNav=function(){var t,e=arguments[0];if(i[e])e=i[e],t=Array.prototype.slice.call(arguments,1);else{if("object"!=typeof e&&e)return s.error("Method "+e+" does not exist in the scrollNav plugin"),this;e=i.init,t=arguments}return e.apply(this,t)}})(jQuery);