/* ========== body ========== */
$(function () {
    $('body').removeClass("initial_loading");
});

/* ========== nav ========== */
function toggle() {
    var header = document.getElementById("header")
    header.classList.toggle('active')
}

$(function () {
    $('.toggle').on('click', function () {
        $(this).toggleClass('active');
        $("header nav").toggleClass('active');
    })
});

$(function () {
    $('header nav a').on('click', function () {
        $('header nav').toggleClass('active');
        $(".toggle").toggleClass('active');
    })
});


/* ========== coupon modal ========== */
$(function(){
    $('.coupon-modal-open').on('click',function(){
        $('.coupon-modal').fadeIn();
        return false;
    });
    $('.coupon-modal-close').on('click',function(){
        $('.coupon-modal').fadeOut();
        return false;
    });
});

/* ========== to top ========== */

$(function () {
    $('.toTop').click(function () {
        $('body,html').animate({
            scrollTop: 0
        }, 800);
        return false;
    });
});

$(function () {
    var pagetop = $('.totop');
    pagetop.hide();
    $(window).scroll(function () {
        if ($(this).scrollTop() > 100) {
            pagetop.fadeIn();
        } else {
            pagetop.fadeOut();
        }
    });

    pagetop.click(function () {
        $('body, html').animate({scrollTop: 0}, 500);
        return false;
    });
});


/* ============ fadein ============== */
$(function () {
    $('.fadein').css('visibility', 'hidden');
    $(window).scroll(function () {
        var windowHeight = jQuery(window).height(),
            topWindow = jQuery(window).scrollTop();
        $('.fadein').each(function () {
            var targetPosition = jQuery(this).offset().top;
            if (topWindow > targetPosition - windowHeight + 100) {
                jQuery(this).addClass("fadeInDown");
            }
        });
    });
});

$(function () {
    $('ul.cast-list li')
        .css({opacity: 0})
        .each(function (i) {
            $(this).delay(200 * i).animate({opacity: 1, top: -10}, 1000);
        });
});

$(function () {
    $('.delay li')
        .css({opacity: 0})
        .each(function (i) {
            $(this).delay(200 * i).animate({opacity: 1, top: -10}, 1000);
        });
});


$(function () {
    $('.cast-cb .blog-item')
        .css({opacity: 0})
        .each(function (i) {
            $(this).delay(300 * i).animate({opacity: 1, top: -10}, 1000);
        });
});

$(function () {
    $('.delay .blog-item')
        .css({opacity: 0})
        .each(function (i) {
            $(this).delay(200 * i).animate({opacity: 1, top: -10}, 1000);
        });
});


$(function () {
    $(window).scroll(function () {
        $('.slidein').each(function () {
            var elemPos = $(this).offset().top;
            var scroll = $(window).scrollTop();
            var windowHeight = $(window).height();
            if (scroll > elemPos - windowHeight + 150) {
                $(this).addClass('scrollin');
            }
        });
    });
});

$(function () {
    $('.mv-text_sp').hide().fadeIn(1500),
        $('.mv-text_pc').hide().fadeIn(1500);
});

$(function () {
    // $('.cast-cl .sec-title').hide().fadeIn(1000),
    $('.slow').hide().fadeIn(1500);
});

/* ========== video ========== */
$(function () {
    let isFullScreen = false;
    $('#video').on('click', function (event) {
        let elem = event.target;

        if (isFullScreen) {
            if (document.exitFullscreen) {
                document.exitFullscreen();
            } else if (document.mozCancelFullScreen) { /* Firefox */
                document.mozCancelFullScreen();
            } else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
                document.webkitExitFullscreen();
            } else if (document.msExitFullscreen) { /* IE/Edge */
                document.msExitFullscreen();
            }

            return isFullScreen = false;
        }

        if (elem.requestFullscreen) {
            elem.requestFullscreen();
        } else if (elem.mozRequestFullScreen) { /* Firefox */
            elem.mozRequestFullScreen();
        } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
            elem.webkitRequestFullscreen();
        } else if (elem.msRequestFullscreen) { /* IE/Edge */
            elem.msRequestFullscreen();
        }
        elem.play();

        return isFullScreen = true;
    });
});
