// navbar
$('.toggle').click(function () {
    $('.nav-list, .toggle').toggleClass('active')
    // $('.nav-list.active').addClass('animate__slideInRight')
});

$('.nav-item').click(function () {
    $('.nav-list, .toggle').removeClass('active')
    // $('.nav-list.active').addClass('animate__slideOutRight')
});

// privacy & copyright{
$('[data-toggle="lightbox"]').on('click', function () {
    $('#' + $(this).attr('data-target')).addClass('show');
})
$('.close').on('click', function () {
    $('.lightbox').removeClass('show');
})


// map
$('.map a').on('click', function () {
    var city = $(this).attr('data');
    $('#city').val(city);
    cityChange(city, this);
})

$('#city').on('change', function () {
    var city = $(this).val();
    cityChange(city, '.map a[data="' + city + '"]');
})

function cityChange(city, e) {
    $('.map a').removeClass('active');
    $(e).addClass('active');
    $('#area').empty();
    $('#area').append('<option value="" selected="selected">-- 地區 --</option>');
    $('#area').append($('#' + city).html());
}


// youtube
var addVideo = '<div id="ytplayer"></div>';

$('a.video-link').on('click', function () {
    var videoID = $(this).attr('data');
    $('#play').html(addVideo);
    $('#video').addClass('show-video');
    playYoutube(videoID);
})
$('.close').on('click', function () {
    $('#video').removeClass('show-video');
})

// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// Replace the 'ytplayer' element with an <iframe> and
// YouTube player after the API code downloads.
var player;

function playYoutube(videoID) {
    player = new YT.Player('ytplayer', {
        // height: '360',
        // width: '640',
        videoId: videoID,
        autoplay: 1,
    });

}

$(window).scroll(function () {
    var N = $(window).scrollTop()
    // top
    if (N > 500) {
        $('.top').addClass('show-top')

    } else {
        $('.top').removeClass('show-top')
    }
})

// 錨點
$('.top').click(function () {
    $("html, body").animate({ scrollTop: 0 }, 1000, 'swing');
    return false;
});