if ($(".navigation").length) {
  $(".navigation .navbar button").on("click", function () {
    $(".navigation .menu").slideToggle();
    $(this).toggleClass("open");
    return false;
  });
  $(".navigation .cs-submenu")
    .children("a")
    .append(function () {
      return '<button class="dropdown-expander"><i class="fa fa-chevron-down"></i></button>';
    });
  $(".navigation .menu .dropdown-expander").on("click", function () {
    $(this).parent().parent().children(".cs-dropdown").slideToggle();
    console.log($(this).parents("li"));
    return false;
  });
}

if (document.documentElement.clientWidth < 980) {
  $(document).click(function (e) {
    if (!$(e.target).closest(".navigation .navbar button").length) {
      $(".menu").stop(true).slideUp();
      $(".navigation .navbar button").removeClass("open");
    }
  });
}

$(document).ready(function () {
  //Carousal

  $(".blog-carousel").owlCarousel({
    loop: true,
    margin: 25,
    dots: false,
    responsiveClass: true,
    responsive: {
      0: {
        items: 1,
        nav: true,
      },
      600: {
        items: 1,
        nav: true,
      },
      820: {
        items: 2,
        nav: true,
      },
      1200: {
        items: 3,
        nav: true,
        loop: true,
      },
    },
  });

  $(".product-carousel").owlCarousel({
    loop: true,
    margin: 15,
    mouseDrag: true,
    autoplay: true,
    dots: false,
    smartSpeed: 1000,
    responsiveClass: true,
    responsive: {
      0: {
        items: 1,
        nav: true,
      },
      600: {
        items: 2,
        nav: true,
      },
      820: {
        items: 2,
        nav: true,
      },
      1200: {
        items: 4,
        nav: true,
        loop: true,
      },
    },
  });

  $(".banner-carousel").owlCarousel({
    loop: true,
    margin: 15,
    mouseDrag: true,
    autoplay: true,
    dots: false,
    smartSpeed: 1000,
    responsiveClass: true,
    responsive: {
      0: {
        items: 1,
        nav: true,
      },
      768: {
        items: 1,
        nav: true,
      },
      992: {
        items: 1,
        nav: true,
      },
      1200: {
        items: 1,
        nav: true,
        loop: true,
      },
    },
  });

  $(".seller-carousel").owlCarousel({
    loop: true,
    margin: 15,
    mouseDrag: true,
    autoplay: true,
    dots: false,
    smartSpeed: 1000,
    responsiveClass: true,
    responsive: {
      0: {
        items: 1,
        nav: true,
      },
      600: {
        items: 2,
        nav: true,
      },
      820: {
        items: 2,
        nav: true,
      },
      1200: {
        items: 3,
        nav: true,
        loop: true,
      },
    },
  });

  $(".abroadSlider").owlCarousel({
    loop: true,
    margin: 15,
    mouseDrag: true,
    autoplay: true,
    dots: false,
    smartSpeed: 1000,
    responsiveClass: true,
    responsive: {
      0: {
        items: 1,
        nav: true,
      },
      600: {
        items: 2,
        nav: true,
      },
      820: {
        items: 2,
        nav: true,
      },
      1200: {
        items: 3,
        nav: true,
        loop: true,
      },
    },
  });

  $(".testimonial-carousel").owlCarousel({
    loop: true,
    margin: 15,
    mouseDrag: true,
    autoplay: true,
    dots: false,
    smartSpeed: 1000,
    responsiveClass: true,
    responsive: {
      0: {
        items: 1,
        nav: true,
      },
      600: {
        items: 2,
        nav: false,
      },
      1000: {
        items: 2,
        nav: true,
        loop: true,
      },
    },
  });

  $(document).on("click", ".sidebar_heading a.sidebar_toggle", function (e) {
    var $this = $(this);
    if (!$this.hasClass("sidebar_collapsed")) {
      $this.parents(".sidebar_group").find(".sidebar_inner").slideUp();
      $this.addClass("sidebar_collapsed");
      /*$this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');*/
    } else {
      $this.parents(".sidebar_group").find(".sidebar_inner").slideDown();
      $this.removeClass("sidebar_collapsed");
      /*$this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');*/
    }
  });

  //$(function() {
  //    $("#slider-range").slider({
  //        range: true,
  //        min: 0,
  //        max: 5000,
  //        values: [50, 4000],
  //        slide: function(event, ui) {
  //            $("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);
  //        }
  //    });
  //    $("#amount").val("$" + $("#slider-range").slider("values", 0) +
  //        " - $" + $("#slider-range").slider("values", 1));
  //});

  //cart-drop-down
  $(".cart-btn").click(function () {
    $(".cart-dropdown").toggleClass("show");
    $(".overlay3").toggleClass("show");
  });

  //cart-drop-down
  $(".cart-btn").click(function () {
    $(".overlay3").addClass("myCanvasNav");
  });

  //cart-drop-down
  $("#myCanvasNav").click(function () {
    $(".overlay3").removeClass("show");
    $(".cart-dropdown").removeClass("show");
    $(this).addClass("hide");
  });

  //Sticky Header
  $(window).scroll(function () {
    if ($(window).scrollTop() >= 330) {
      $(".navigation").addClass("fixed");
    } else {
      $(".navigation").removeClass("fixed");
    }
  });

  //Sidebar

  $(".sub-btn").click(function () {
    $(this).next(".sub-menu").slideToggle();
    $(this).find(".dropdown").toggleClass("rotate");
  });

  $(".menu-btn").click(function () {
    $(".side-bar").addClass("active");
    $(this).css("visibility", "hidden");
  });

  $(".close-btn").click(function () {
    $(".side-bar").removeClass("active");
    $(".menu-btn").css("visibility", "visible");
  });

  $(".icon-btn").click(function () {
    $(".side-bar").toggleClass("responsive");
  });
});
