// source --> https://lescollectionsaquam.ca/wp-content/themes/collections/js/script.js?ver=83d71ed8dd98d6a7892ea933dca9f2d3 
$( document ).ready(function() {
    $("#menu-menu-principal a").each(function(i){
        let currentText = $(this).text();
        $(this).html("<span>" + currentText + "</span>");
    });

    $('.carrousel').slick({
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 5000,
        prevArrow: $('.prev'),
        nextArrow: $('.next'),
    });

    $('.product-image').slick({
        slidesToShow: 1,
        slidesToScroll: 1,
        arrows: true,
        prevArrow: $('.prev'),
        nextArrow: $('.next'),
        infinite: false,
        asNavFor: '.product-carrousel',
        draggable: false,
        dots: false,
        focusOnSelect: true,
    });

    $('.product-carrousel').slick({
        slidesToShow: 3,
        slidesToScroll: 3,
        infinite: false,
        asNavFor: '.product-image',
        dots: false,
        arrows: false,
        //draggable: true,
        focusOnSelect: true,

    });

    $('.zoom-image').zoom();

    /*$('.product-image').on("click", function(){
        toggleImageOnClick($(this).find(".slick-current").attr('src'));
    });

    $("#show-big-image").on("click", function(){
        toggleImageOnClick();
    });

    function toggleImageOnClick(source = ''){
        console.log("test");
        if(source == ""){
            $("#show-big-image").css("display", "none");
        }
        else{
            $("#show-big-image img").attr("src", source);
            $("#show-big-image").css("display", "block");
        }
        console.log(source);
    }*/

    let parallaxImg = $('.parallax img').attr("src");

    $('.parallax-container').css({
        "background-image" : 'url("' + parallaxImg + '")',
    });

    $('p.mot').prepend('<i class="fas fa-angle-double-down"></i>');

    $("#back_to_top").on("click", function(){
        window.scrollTo({
            top : 0,
            left : 0,
            behavior : "smooth",
        });
    });

    $("#back_to_top").mouseenter(function(){
        $(this).css("opacity", 1);
    });

    $("#back_to_top").mouseleave(function(){
        $(this).css("opacity", 0.5);
    });

    $(window).scroll(function (event) {
        var scroll = $(window).scrollTop();
        var toTop = $("#back_to_top");
        if(scroll > 500){
            toTop.css("opacity", 0.5);
        }else{
            toTop.css("opacity", 0);
        }
        // Do something
    });

    var images =  $("ul.products li.product img");

    images.each(function(){
        $(this).wrap("<div class='product-image-container'></div>");
    });
    //$("ul.products li.product img").html("<div class='product-image'>" + $(this).html() + "</div>");

    $("div.menu-opener").on("click",function(){
        let links = $("div.links");

        if(links.css("display") === "none"){
            links.css("display", "block");
        }else{
            links.css("display", "none");
        }

        links.css({
            height: "toggle"
        }, 0);
    });

    $("div.links .sub-menu").parent().each(function(){
        var model = $(".icon-template").clone();
        model.removeClass("icon-template");
        model.addClass("icon");
        $(this).append(model);
    });

    $(".icon").on("click", function(){
        if($(this).find("i").hasClass("fa-angle-right")){
            $(this).find("i").removeClass("fa-angle-right");
            $(this).find("i").addClass("fa-angle-down");
            $(this).siblings("ul.sub-menu").css("display", "block");
        }else{
            $(this).find("i").removeClass("fa-angle-down");
            $(this).find("i").addClass("fa-angle-right");
            $(this).siblings("ul.sub-menu").css("display", "none");
        }

    });

    $("div.header-mobile .links ul a").each(function() {
        if ($(this).attr('href') === window.location.href) {
            $(this).addClass("current_page");
        }
    });

});