jQuerOs(document).ready(function () {

  var sidebarRightMenu = jQuerOs('.sidebar-right-menu');
  sidebarRightMenu.find('li.parent > a, li.parent > .nav-header').append('<i class="fas fa-angle-double-left"></i>');
  sidebarRightMenu.find(' > li').last().addClass('lastChild');

  var sidebarLeftMenu = jQuerOs('.sidebar-left-menu');
  sidebarLeftMenu.find('li.parent > a, li.parent > .nav-header').append('<i class="fas fa-angle-double-right"></i>');
  sidebarLeftMenu.find(' > li').last().addClass('lastChild');

  jQuerOs('.itp-subscribe form .inputbox').attr('placeholder', 'Email Address');

  var wrapheight = jQuerOs(window).outerHeight() - jQuerOs(".header").outerHeight(true) - jQuerOs("#footer").outerHeight(true);
  jQuerOs("#wrapper").css("min-height", wrapheight);

  jQuerOs(document).ready(function () {
    jQuerOs(".main_menu .navbar-toggle").click(function () {
      if (jQuerOs(".main_menu #main-navbar-collapse").hasClass("activeMenu")) {
        jQuerOs(".main_menu #main-navbar-collapse").removeClass("activeMenu");
        jQuerOs(".main_menu #main-navbar-collapse").addClass("menuInActive");
        jQuerOs(".main_menu #main-navbar-collapse").slideDown();
      } else {
        jQuerOs(".main_menu #main-navbar-collapse").removeClass("menuInActive");
        jQuerOs(".main_menu #main-navbar-collapse").addClass("activeMenu");
        jQuerOs(".main_menu #main-navbar-collapse").slideUp();
      }
    });
  });


  jQuerOs('#search-form .js-finder-searchform .form-inline .input-group .btn-secondary').on('click', function () {
    jQuerOs('#search-form #advancedSearch').toggleClass('active');
    jQuerOs('#search-form .js-finder-searchform .form-inline .input-group .btn-secondary .icon-search-plus').toggleClass('minus');
  });

  jQuerOs('#modules-form #options #collapseTypes .accordion-item .accordion-button').on('click', function () {
    const item = jQuerOs(this).closest('.accordion-item'); // ближайший accordion-item

    item.find('.accordion-collapse').toggleClass('active');
    item.find('.accordion-button').toggleClass('active');
  });


  // 

  const menuItems = document.querySelectorAll('.menu .parent');

  function addClassToParent(event) {
    const menuItem = event.target;
    menuItem.parentElement.classList.add('focus');
  }

  function removeClassFromParent(event) {
    const menuItem = event.target;
    menuItem.parentElement.classList.remove('focus');
  }

  menuItems.forEach(item => {
    item.addEventListener('mouseenter', addClassToParent);
    item.addEventListener('mouseleave', removeClassFromParent);

    item.addEventListener('focusin', addClassToParent);
    item.addEventListener('focusout', removeClassFromParent);

    const subMenu = item.querySelector('.nav-child');
    if (subMenu) {
      subMenu.addEventListener('mouseenter', addClassToParent);
      subMenu.addEventListener('mouseleave', removeClassFromParent);

      subMenu.addEventListener('focusin', function () {
        item.classList.add('focus');
      });
      subMenu.addEventListener('focusout', function () {
        item.classList.remove('focus');
      });
    }
  });






  // _____________________________________________________________________________________________ footer to bottom
  function footerToBottom() {
    var browserHeight = jQuerOs(window).height(),
      footerOuterHeight = jQuerOs('.footer').outerHeight(true),
      mainHeightMarginPaddingBorder = jQuerOs('#wrapper').outerHeight(true) - jQuerOs('#wrapper').height() + 3;
    jQuerOs('#wrapper').css({
      'min-height': browserHeight - footerOuterHeight - mainHeightMarginPaddingBorder,
    });
  };
  footerToBottom();
  jQuerOs(window).resize(function () {
    footerToBottom();
  });

});

jQuerOs(document).ready(function () {

  var mainMenu = jQuerOs('#site-navigation-main ul.nav');
  mainMenu.find('li.parent > a').next('ul').hide();
  mainMenu.find('li.parent > a').append('<i class="fas fa-angle-down"></i>');
  mainMenu.find('li.parent > span.separator').next('ul').hide();
  mainMenu.find('li.parent > span.separator').append('<i class="fas fa-angle-down"></i>');
  mainMenu.find('li.parent > .nav-header').next('ul').hide();
  mainMenu.find('li.parent > .nav-header').append('<i class="fas fa-angle-down"></i>');
  mainMenu.find('li.parent .mod-menu__heading').append('<i class="fas fa-angle-down"></i>');


  var sidebarMenu = jQuerOs('div[class*="sidebar"] .mod-menu');
  sidebarMenu.find('li.parent > a').append('<i class="fas fa-angle-down"></i>');
  sidebarMenu.find('li.parent > span.separator').append('<i class="fas fa-angle-down"></i>');
  sidebarMenu.find('li.parent > .nav-header').append('<i class="fas fa-angle-down"></i>');
  sidebarMenu.find('li.parent .mod-menu__heading').append('<i class="fas fa-angle-down"></i>');

  jQuerOs(function () {

    mainMenu.find('li.parent').hover(function () {

      if (!jQuerOs(this).children('ul').is(':visible')) {
        jQuerOs(this).children('ul').stop().slideDown(50);
      }
    },
      function () {
        if (jQuerOs(this).children('ul').is(':visible')) {
          jQuerOs(this).children('ul').slideUp(50);
        }
      });
  });
});

jQuerOs(window).scroll(function () {
  var topPos = jQuerOs(this).scrollTop();
  if (topPos > 10) {
    jQuerOs('.header').addClass('fixed');
  } else {
    jQuerOs('.header').removeClass('fixed');
  }
});