$(document).ready(function () {
    function o(o) {
        o.matches ? $(document).ready(function () {
            $(".scrollsmooth").click(function (o) {
                o.preventDefault();
                var e = +$($(this).attr("href")).offset().top;
                $("body, html").animate({
                    scrollTop: e
                }, 800)
            })
        }) : $(document).ready(function () {
            $(".scrollsmooth").click(function (o) {
                o.preventDefault();
                var e = +$($(this).attr("href")).offset().top;
                $("body, html").animate({
                    scrollTop: e
                }, 800)
            })
        })
    }
    var e = window.matchMedia("(max-width: 1080px)");
    o(e), e.addListener(o)

    $(window).scroll(function () {
        if ($(this).scrollTop() > 200) {
            $('header').addClass('with-bg');
        } else {
            $('header').removeClass('with-bg');
        }
    });

    $(".nav-icon").click(function () {
        $(".nav-icon").toggleClass("open");
        $(".menu-responsive").toggleClass("active");
    });

    $(".btn-dropdown-01").click(function () {
        $(".btn-dropdown-01").addClass("active");
        $(".content-dropdown-01").slideDown();
    });
    $(".btn-close-dropdown").click(function () {
        $(".content-dropdown-01").slideUp();
        $(".btn-dropdown-01").removeClass("active");
    });

    // Slide Content //
    $(".toggle-btn").click(function () {
        if ($(this).hasClass("faq-btn")) {
            return '';
        }

        var target = $(this).parent().children(".toggle-content");
        var target2 = $(this).parent().children(".toggle-btn");
        $(target).slideToggle();
        $(target2).toggleClass('active');
    });
    $(".before-btn-sub").click(function () {
        var target = $(this).parent().children(".before-toggle-sub");
        var target2 = $(this).parent().children(".before-btn-sub");
        $(target).slideToggle();
        $(target2).toggleClass('active');
    });


    $(window).scroll(function () {
        250 <= $(this).scrollTop() ? $(".gototop").fadeIn(250) : $(".gototop").fadeOut(250)
    });

    $(".gototop").click(function () {
        $("body,html").animate({
            scrollTop: 0
        }, 1e3)
    });

    $('img').on('dragstart', function (event) { event.preventDefault(); });

    if (!(location.pathname === '/' && $(":target").length > 0)) { // idを含むtop画面のURL以外
        window.wow = new WOW();
        wow.init();
    }

    $(":target").children(".toggle-btn").trigger("click");

    if ($(":target").length > 0) {
        $(window).scrollTop(0);
        const id = '#' + $(":target")[0].id
        var e = $($(id)).offset().top;
        $("body, html").animate({
            scrollTop: e
        }, 400)
    }

    document.addEventListener('wheel', function () { }, { passive: true });

    var winH = $(window).height();
    $(window).on('scroll', function () {
        var scroll = $(window).scrollTop();
        var footerTop = $('footer').offset().top;
        if (scroll >= footerTop - winH) {
            $('.btn-cart-sp a').css("display", "none")
        } else {
            $('.btn-cart-sp a').css("display", "")
        }
    });
});

function openLink(url) {
    let countryArray = []
    $('.continent-select option:selected').each((index, element) => {
            let val = $(element).text();
        if (!val.match(/null/) && !val.match(/国を選択してください/)) {
            if (val === 'グアム') {
                val = 'アメリカ（グアム）';
            } else if (val === 'ハワイ') {
                val = 'アメリカ（ハワイ）';
            } else if (val === 'アメリカ合衆国（アラスカ含む）') {
                val = 'アメリカ（本土）';
            }

            countryArray.push(val);
        }
    })

    let param = ''
    if (countryArray.length > 0) {
        param = '?'
        countryArray.forEach((country, index) => {
            if (index !== 0) param = param + '&'
            param = param + 'country_' + (index + 1) + '=' + country
        })
    }

    window.location.href = (url + '/ja' + param)
}