window.onload=function() {
    document.getElementById('preloader').style.display = 'none';
}

$(document).ready(function() {
    // Gets the video src from the data-src on each button
    
    let $videoSrc;
    let $pictureSrc;

    $('.picture-btn').click(function() {
        $pictureSrc = $(this).data( "src" );
    });

    $('#gallery-picture-modal').on('shown.bs.modal', function (e) {
        $("#picture").attr('src',$pictureSrc);
    })

    $('.video-btn').click(function() {
        $videoSrc = $(this).data( "src" );
    });

    // when the modal is opened autoplay it  
    $('#gallery-video-modal').on('shown.bs.modal', function (e) {
        // set the video src to autoplay and not to show related video. Youtube related video is like a box of chocolates... you never know what you're gonna get
        $("#video").attr('src',$videoSrc + "?autoplay=1&amp;modestbranding=1&amp;showinfo=0");
    })

    // stop playing the youtube video when I close the modal
    $('#gallery-video-modal').on('hide.bs.modal', function (e) {
        // a poor man's stop video
        $("#video").attr('src',$videoSrc); 
    }) 

    $("#navbarSupportedContent").on('show.bs.collapse', function() {
        $('a.nav-link').click(function() {
            $("#navbarSupportedContent").collapse('hide');
        });
    });
});
