jQuery(document).ready(function($){

  var menuRight = document.getElementById( 'cbp-spmenu-s2' ),
    showRightPush = document.getElementById( 'showRightPush' ),
    body = document.body

  showRightPush.onclick = function() {
    classie.toggle( this, 'active' );
    classie.toggle( wrap, 'cbp-spmenu-push-toleft' );
    classie.toggle( menuRight, 'cbp-spmenu-open' );
  };

    $("#wrapper_2, .close_icon").click(function(){
      $("#wrap").removeClass("cbp-spmenu-push-toleft");
      $("#cbp-spmenu-s2").removeClass("cbp-spmenu-open");
      $("#wrapper_2").removeClass("active");
      $(".menu_wrap").removeClass("active");
      $("#showRightPush").removeClass("active");
    });
    $("#showRightPush").click(function(){
      $("#wrapper_2").toggleClass("active");
    });
    $("#showRightPush").click(function(){
      $(".menu_wrap").toggleClass("active");
    });

    $('header .mobile-menu .menu-header-menu-container').meanmenu({
      meanScreenWidth:"960",
      meanMenuContainer:'header > .container-fluid'
    });

    // Open external links in new tab
    $('a[href^=http]').click(function () {
      var a = new RegExp('/' + window.location.host + '/');
      if (!a.test(this.href)) {
        window.open(this.href);
        return false;
      }
    });

    function checkWidth() {
      var windowSize = $(window).width();
      if (windowSize >= 768) {
        $(window).scroll(function() {
          var scroll = $(window).scrollTop();
          if (scroll >= 60) {
            $("#header_wrap").addClass('smaller');

          } else {
            $("#header_wrap").removeClass("smaller");


          }
        });
      } else{
        $(window).scroll(function() {
          var scroll = $(window).scrollTop();
          if (scroll >= 6000) {
            $("#header_wrap").addClass('smaller');

          } else {
            $("#header_wrap").removeClass("smaller");

          }
        });
      }
    }
    // Execute on load
    checkWidth();
    // Bind event listener
    $(window).resize(checkWidth);

    if($('#myCarousel').length) {
      $( '#myCarousel' ).carousel( {
        interval: 4000
      } );
    }

    $(function() {
      $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
          var target = $(this.hash);
          target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
          if (target.length) {
            $('html,body').animate({
              scrollTop: target.offset().top
            }, 1000);
            return false;
          }
        }
      });
    });

    //Fix enter forms
    form_enter_odd();

    function form_enter_odd() {
      $('.fsForm input, .fsForm select').keypress( function (e) {

        let thisForm = $(this).closest('.fsForm');
        let thisSubmit = thisForm.find('.fsSubmitButton');

        if (e.which == 13) {
          thisSubmit.click();
          return false;
        }
      });
    }
  });

