"use strict"

$(document).ready(function() {

  var $navs = $('.main-navigation .nav-wrapper').find('.navigation'),  // navigaion subitems
      // $l_actives = JSON.parse(sessionStorage.getItem('active_entries')),   // active menu entrys from sessionStorage
      $c_actives = [],                                                     // active menu entrys in actual session
      $clicked = {};                                                      // clicked element

  //
  // build current active array based on navigaion subitems
  //
  $.each($navs, function(index) {
    $c_actives.push('0');
  })

  //
  // restore visibile items from sessionStorage
  //
  // if ($l_actives) {
  //   $.each($navs, function(index) {
  //     $c_actives[index] = $l_actives[index];
  //     if ($l_actives[index] == '1') {
  //       $(this).addClass('is-visible')
  //     }
  //   })
  // }

  //
  // handle item click
  //
  $(".nav-wrapper").click(function(e) {
    if (e.target.parentElement.className != 'nav-title') { return; }

    $clicked = $(this).closest('.nav-wrapper');

    // remove is-visibile
    if ($clicked.hasClass('is-open')) {
      $clicked.removeClass('is-open')

      // find clicked item in list of nav items and set sessionStorage
      // $.each($navs, function(index) {
      //   if ($(this).is($clicked)) {
      //     $c_actives[index] = "0";
      //     sessionStorage.setItem('active_entries', JSON.stringify($c_actives));
      //   }
      // })
    }
    // set is-visibile
    else {
      $clicked.addClass('is-open')

      // find clicked item in list of nav items and set sessionStorage
      // $.each($navs, function(index) {
      //   if ($(this).is($clicked)) {
      //     $c_actives[index] = "1";
      //     sessionStorage.setItem('active_entries', JSON.stringify($c_actives));
      //   }
      // })
    } // end if
  }); //end click

}); //end ready
