(function() {
    'use strict';
    Mzp.Navigation.init();
    Mzp.Menu.init();
})();

var toggleNavButtons = document.querySelectorAll('[data-sumo-toggle-nav]');

function resetNavs() {
  var allNavs = document.querySelectorAll('.mzp-c-navigation-items');
  // reset all nav menus
  allNavs.forEach((elm) => {
    elm.setAttribute('aria-expanded', 'false');
    elm.classList.remove('mzp-is-open');
  });
}

if (toggleNavButtons.length > 0) {
  toggleNavButtons.forEach((button) => {
    function toggleMenu() {
      var toggleThisId = button.dataset.sumoToggleNav;
      var toggleThisItem = document.querySelector(toggleThisId);

      if (toggleThisItem.getAttribute('aria-expanded') == 'false') {
        resetNavs();
        toggleThisItem.classList.add('mzp-is-open');
        toggleThisItem.setAttribute('aria-expanded', 'true');

        // if profile nav, go straight to subnav
        if (toggleThisId == "#profile-navigation") {
          toggleThisItem.querySelector('.mzp-js-expandable').classList.add('mzp-is-selected');
        }

        // if search nav, focus the field
        if (toggleThisId == "#search-navigation") {
          window.scrollTo(0,0);
          toggleThisItem.querySelector('.searchbox').focus();
        }


      } else {
        resetNavs();
      }
    }
    button.addEventListener('click', toggleMenu, false);
  });
}

// close navs on resize
var timeout = false;
var width = window.innerWidth;

window.addEventListener('resize', function() {
    clearTimeout(timeout);
    timeout = setTimeout(function(){
      if (window.innerWidth != width) {
        width = window.innerWidth;
        resetNavs
      }
    }, 250);



});

// lang switcher from protocol. #TODO: test this in app.
// (function() {
//   'use strict';
//   // a custom callback can be passed to the lang switcher for analytics purposes.
//   Mzp.LangSwitcher.init(function(
//     previousLanguage, newLanguage) {
//     console.log('Previous language: ',
//       previousLanguage);
//     console.log('New language: ',
//       newLanguage);
//   })
// })();

@@ -1380,16 +1380,134 @@
 n resize
+, but only check width. Height changes on mobile when the%0A// address bar slides away on scroll, which causes problems.
 %0Avar tim
@@ -1551,17 +1551,16 @@
 rWidth;%0A
-%0A
 window.a
@@ -1754,16 +1754,19 @@
 esetNavs
+();
 %0A      %7D
@@ -1779,19 +1779,16 @@
 , 250);%0A
-%0A%0A%0A
 %7D);%0A%0A// 

comment and cleanup for mobile nav fixes