var $ = jQuery.noConflict();

//tab locate function
$(function () {
  var hash = window.location.hash;
  hash && $('ul.nav a[href="' + hash + '"]').tab("show");

  /* $('.nav-tabs a').click(function (e) {
    $(this).tab('show');
    var scrollmem = $('body').scrollTop();
    window.location.hash = this.hash;
    $('html,body').scrollTop(scrollmem);
  });
     */

  $(".product-tabs a").click(function (e) {
    $(this).tab("show");
    var scrollmem = $("body").scrollTop();
    window.location.hash = this.hash;
    $("html,body").scrollTop(scrollmem);
  });
});

//check country

$(function () {
  if (!Cookies.get("geocode_redirect")) {
    var urlpath = window.location.href;
    $.ajax({
      type: "POST",
      url: "https://www.crigroups.com/geocode/geo.phtml",
      data: { urlpath: urlpath },
      cache: false,
      success: function (data) {
        console.log(data["redirect"]);
        if (data["redirect"] == true) {
          $("#countrymodel").modal("show");
          Cookies.set("geocode_redirect", "true", { expires: 1, path: "/" });
        }
      },
    });
  }
});

//wow function initialize.
jQuery(document).ready(function ($) {
  new WOW().init();
});

//swiper functions

var relatedProductcarousal = new Swiper(".related-product-carousel", {
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
  breakpointsInverse: true,
  breakpoints: {
    320: {
      slidesPerView: 1,
      spaceBetween: 0,
    },
    768: {
      slidesPerView: 3,
      spaceBetween: 0,
    },
    1200: {
      slidesPerView: 3,
      spaceBetween: 30,
    },
  },
  autoplay: {
    delay: 2000,
  },
});

var brandsCarousal = new Swiper(".brands-carousel", {
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
  breakpointsInverse: true,
  breakpoints: {
    320: {
      slidesPerView: 1,
      spaceBetween: 0,
    },
    768: {
      slidesPerView: 3,
      spaceBetween: 0,
    },
    1200: {
      slidesPerView: 6,
      spaceBetween: 30,
    },
  },
  autoplay: {
    delay: 2000,
  },
});

var productCarousal = new Swiper(".product-carousel", {
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
  breakpointsInverse: true,
  breakpoints: {
    1200: {
      slidesPerView: 1,
      spaceBetween: 1,
    },
  },
  autoplay: {
    delay: 3000,
  },
});

var applicationCarousal = new Swiper(".application-carousel", {
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
  breakpointsInverse: true,
  breakpoints: {
    320: {
      slidesPerView: 1,
      spaceBetween: 0,
    },
    768: {
      slidesPerView: 3,
      spaceBetween: 0,
    },
    1200: {
      slidesPerView: 5,
      spaceBetween: 30,
    },
  },
  autoplay: {
    delay: 3000,
  },
});

var homeCarousal = new Swiper(".home-carousel", {
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
  breakpointsInverse: true,
  breakpoints: {
    1200: {
      slidesPerView: 1,
      spaceBetween: 1,
    },
  },
  autoplay: {
    delay: 3000,
  },
});

var brancheCarousal = new Swiper(".branche-carousel", {
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
  breakpointsInverse: true,
  breakpoints: {
    320: {
      slidesPerView: 1,
      spaceBetween: 0,
    },
    768: {
      slidesPerView: 3,
      spaceBetween: 0,
    },
    1200: {
      slidesPerView: 5,
      spaceBetween: 30,
    },
  },
  autoplay: {
    delay: 3000,
  },
});

var pipesCarousal = new Swiper(".pipes-carosel ", {
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
  navigation: {
    nextEl: ".swiper-button-next",
    prevEl: ".swiper-button-prev",
  },
  breakpointsInverse: true,
  breakpoints: {
    320: {
      slidesPerView: 1,
      spaceBetween: 40,
    },
    768: {
      slidesPerView: 1,
      spaceBetween: 30,
    },
    1200: {
      slidesPerView: 1,
      spaceBetween: 12,
    },
  },
  autoplay: {
    delay: 2900,
  },
});

$(document).ready(function () {
  $(".toggle-accordion").on("click", function () {
    var accordionId = $(this).attr("accordion-id"),
      numPanelOpen = $(accordionId + " .collapse.in").length;

    $(this).toggleClass("active");

    if (numPanelOpen == 0) {
      openAllPanels(accordionId);
    } else {
      closeAllPanels(accordionId);
    }
  });

  openAllPanels = function (aId) {
    console.log("setAllPanelOpen");
    $(aId + ' .panel-collapse:not(".in")').collapse("show");
  };
  closeAllPanels = function (aId) {
    console.log("setAllPanelclose");
    $(aId + " .panel-collapse.in").collapse("hide");
  };
});




 
