// SIDEBAR MENU 

function hasClass(ele, cls) {
  return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)"));
}

function addClass(ele, cls) {
  if (!hasClass(ele, cls)) ele.className += " " + cls;
}

function removeClass(ele, cls) {
  if (hasClass(ele, cls)) {
    var reg = new RegExp("(\\s|^)" + cls + "(\\s|$)");
    ele.className = ele.className.replace(reg, " ");
  }
}

//Add event from js the keep the marup clean
function init() {
  document
    .getElementById("open-menu")
    .addEventListener("click", toggleMenu);
  document
    .getElementById("body-overlay")
    .addEventListener("click", toggleMenu);

}

//The actual fuction
function toggleMenu() {
  var ele = document.getElementsByTagName("body")[0];
  if (!hasClass(ele, "menu-open")) {
    addClass(ele, "menu-open");
    console.log('cliiiick');


  } else {
    removeClass(ele, "menu-open");
    console.log('rrr');

  }
}

//Prevent the function to run before the document is loaded
document.addEventListener("readystatechange", function() {
  if (document.readyState === "complete") {
    init();
  }
});


// ------------------------------------------------
// Sticky Header
var className = "inverted";
var scrollTrigger = 20;

window.onscroll = function() {
  if (window.scrollY >= scrollTrigger || window.pageYOffset >= scrollTrigger) {
    document.getElementsByClassName("navigation-wrap")[0].classList.add(className);
  } else {
    document.getElementsByClassName("navigation-wrap")[0].classList.remove(className);
  }
};

$(window).on("load", function() {
  $(".se-pre-con").fadeOut("slow");;
});



// 


$('.sidebar--nav--menu--wrap .caret').on('click', function(e) {
  e.stopPropagation();
  $('.sidebar--nav--menu--wrap ul ul').slideUp();
  $(this).next().is(":visible") || $(this).next().slideDown();
});

// $('li').has('ul').find('i').not('ul ul a i').addClass('caret');






// 
$(".pegahealth--offers--item--back").css('display', 'none');
$(".overlay").css('display', 'none');

$(".pegahealth--offers--item--front").click(function() {
    $(".pegahealth--offers--item--back").stop().slideUp(300);
    $(this).next(".pegahealth--offers--item--back").stop().slideToggle(300);
    $(".close").show()
    $(".overlay").css('display', 'block');
    $(".pegahealth--offers--item--back").css('visibility', 'visible');
});

$(".close").click(function() {
    $(".pegahealth--offers--item--back").stop().slideUp(300);
    $(".overlay").css('display', 'none');
});
$(".overlay").click(function() {
    $(".pegahealth--offers--item--back").stop().slideUp(300);
    $(".overlay").css('display', 'none');
});


// 
$(".pegahealth--values--wrapper--item--back").css('display', 'none');
$(".overlay").css('display', 'none');

$(".pegahealth--values--wrapper--item--front").click(function () {
  $(".pegahealth--values--wrapper--item--back").stop().slideUp(300);
  $(this).next(".pegahealth--values--wrapper--item--back").stop().slideToggle(300);
  $(".close").show()
  $(".overlay").css('display', 'block');
  $(".pegahealth--values--wrapper--item--back").css('visibility', 'visible');
});

$(".close").click(function () {
  $(".pegahealth--values--wrapper--item--back").stop().slideUp(300);
  $(".overlay").css('display', 'none');
});
$(".overlay").click(function () {
  $(".pegahealth--values--wrapper--item--back").stop().slideUp(300);
  $(".overlay").css('display', 'none');
});



