/*
Theme Name: Flatsome Child
Description: This is a child theme for Flatsome Theme
Author: UX Themes
Template: flatsome
Version: 3.0
*/

/*************** ADD CUSTOM CSS HERE.   ***************/


@media only screen and (max-width: 48em) {
/*************** ADD MOBILE ONLY CSS HERE  ***************/


}
add_action('wp_footer', function() {
?>

<script>

jQuery(document).ready(function ($) {

function loadVideo(videoId) {

let newSrc =
'https://www.youtube.com/embed/' +
videoId +
'?rel=0&autoplay=1';

$('#vinhdanh-iframe')
.fadeOut(200,function(){

$(this)
.attr('src', newSrc)
.fadeIn(200);

});

}



// click thumbnail

$('.content-video-vinhdanh .openVideo')
.on('click', function () {

let videoId =
$(this).data('youtube-id');

$('.content-video-vinhdanh .openVideo')
.removeClass('active');

$(this)
.addClass('active');

loadVideo(videoId);

});




// auto load first video

let $firstVideo =
$('.content-video-vinhdanh .openVideo.active');

if ($firstVideo.length === 0) {

$firstVideo =
$('.content-video-vinhdanh .openVideo')
.first()
.addClass('active');

}


let firstVideoId =
$firstVideo.data('youtube-id');


if (firstVideoId) {

loadVideo(firstVideoId);

}


});

</script>

<?php
});
									add_action('wp_footer', function() {
?>

<script>

if (typeof jQuery !== "undefined") {

jQuery(document).ready(function ($) {

function loadVideo(videoId) {

let newSrc =
'https://www.youtube.com/embed/' +
videoId +
'?rel=0&autoplay=1';

$('#vinhdanh-iframe')
.stop(true,true)
.fadeOut(200,function(){

$(this)
.attr('src', newSrc)
.fadeIn(200);

});

}



// click thumbnail

$(document).on('click',
'.content-video-vinhdanh .openVideo',
function () {

let videoId =
$(this).data('youtube-id');

$('.content-video-vinhdanh .openVideo')
.removeClass('active');

$(this)
.addClass('active');

loadVideo(videoId);

});




// auto load first video

let $firstVideo =
$('.content-video-vinhdanh .openVideo.active');

if ($firstVideo.length === 0) {

$firstVideo =
$('.content-video-vinhdanh .openVideo')
.first()
.addClass('active');

}


let firstVideoId =
$firstVideo.data('youtube-id');


if (firstVideoId) {

loadVideo(firstVideoId);

}


});

}

</script>

<?php
});