function initVideoPlayerElements() {

    if (typeof videojs == 'undefined') {
        console.warn('Warning - video.js is not loaded.');
        return;
    }

    setVideoPlayerButtons();
    setVideoPlayerModals();
    setVideos();

}
function setVideoPlayerModals() {

    let videoPlayerCounter = 0;

    $('.LimitlessVideoPlayerModal').each(function() {

        videoPlayerCounter++;
        let videoPlayerElement = $(this);

        videoPlayerElement.attr('id', 'LimitlessVideoPlayerModal' + videoPlayerCounter);

        let closeButton = videoPlayerElement.find('.LimitlessVideoPlayerClose');
        let videoPlayer = videoPlayerElement.find('.LimitlessVideoPlayer');
        let videoPlayerId = 'LimitlessVideoPlayer' + videoPlayerCounter;

        closeButton.attr('id', 'LimitlessVideoPlayerClose' + videoPlayerCounter);
        videoPlayer.attr('id', videoPlayerId);
    });

}

function setVideoPlayerButtons() {

    let videoPlayerCounter = 0;

    $('.LimitlessVideoPlayerButton').each(function() {

        videoPlayerCounter++;
        let videoPlayerElement = $(this);

        videoPlayerElement.attr('id', 'LimitlessVideoPlayerButton' + videoPlayerCounter);
        videoPlayerElement.attr('data-target', '#LimitlessVideoPlayerModal' + videoPlayerCounter);
    });

}

function setVideos() {

    let videoPlayerElementObjects = $('.LimitlessVideoPlayer');

    videoPlayerElementObjects.each(function() {
        videojs($(this)[0]);
    });

}

$(document).ready(function() {

    initVideoPlayerElements();

    // pauses the video after modal close.
    $('.LimitlessVideoPlayerModal').modal({
        show: false
    }).on('hidden.bs.modal', function(){
        $(this).find('video')[0].pause();
    });

});
