(function localFileVideoPlayer() {
	'use strict'
  var URL = window.URL || window.webkitURL
  var displayMessage = function (message, isError) {
    var element = document.querySelector('#message')
    element.innerHTML = message
    element.className = isError ? 'error' : 'info'
  }
  var playSelectedFile = function (event) {
    var file = this.files[0]
    var type = file.type
    var videoNode = document.querySelector('video')
    var canPlay = videoNode.canPlayType(type)
    if (canPlay === '') canPlay = 'no'
    var message = '<i class="fa fa-info-circle"></i>&nbsp;Can play type "' + type + '": ' + canPlay
    var isError = canPlay === 'no'
    displayMessage(message, isError)

    if (isError) {
      return
    }

    var fileURL = URL.createObjectURL(file)
    videoNode.src = fileURL
  }
  var inputNode = document.querySelector('input')
  inputNode.addEventListener('change', playSelectedFile, false)
})()

// Snackbar
function ShowSnackBar() {
  var x = document.getElementById("snackbar");
  x.className = "show";
  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}

// Back Button
function ShowBackBTN_id0() {
  document.getElementById("FMP_BackBTN_id0").style.display = "block";
}

function HideBackBTN_id0() {
  document.getElementById("FMP_BackBTN_id0").style.display = "none";
}

function ShowBackBTN_id1() {
  document.getElementById("FMP_BackBTN_id1").style.display = "block";
}

function HideBackBTN_id1() {
  document.getElementById("FMP_BackBTN_id1").style.display = "none";
}

function ShowBackBTN_id2() {
  document.getElementById("FMP_BackBTN_id2").style.display = "block";
}

function HideBackBTN_id2() {
  document.getElementById("FMP_BackBTN_id2").style.display = "none";
}

// Dark mode
function createjscssfile(filename, filetype){
    if (filetype=="js"){
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype=="css"){
        var fileref=document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    return fileref
}

function replacejscssfile(oldfilename, newfilename, filetype){
    var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using
    var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
    var allsuspects=document.getElementsByTagName(targetelement)
    for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
        if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){
            var newelement=createjscssfile(newfilename, filetype)
            allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
        }
    }
}

// Playback/Audio Controls
var vid = document.getElementById("my-video");

function playVid() {
  vid.play();
}

function pauseVid() {
  vid.pause();
}

function enableLoop() {
  vid.loop = true;
  vid.load();
}

function disableLoop() {
  vid.loop = false;
  vid.load();
}

function enableMute() {
  vid.muted = true;
}

function disableMute() {
  vid.muted = false;
}

function playbackRateSlower() {
  vid.playbackRate = 0.25;
}

function playbackRateSlow() {
  vid.playbackRate = 0.5;
}

function playbackRateNormal() {
  vid.playbackRate = 1;
}

function playbackRateFast() {
  vid.playbackRate = 1.5;
}

function playbackRateFaster() {
  vid.playbackRate = 2;
}


// PiP Mode
const video = document.querySelector('video');
const button = document.getElementById('pip_mode');

if (!document.pictureInPictureEnabled) {
    button.disabled = true;
    button.textContent = 'PiP is not supported in your browser';
}
if (video.disablePictureInPicture) {
    button.disabled = true;
    button.textContent = 'PiP is currently disabled';
}

button.addEventListener('click', () => {
    if (document.pictureInPictureElement) {
        document.exitPictureInPicture().catch(console.error);
    } else {
        video.requestPictureInPicture().catch(console.error);
    }
});

video.addEventListener('enterpictureinpicture', () => {
    button.textContent = 'Exit PiP Mode';
});

video.addEventListener('leavepictureinpicture', () => {
    button.textContent = 'Enter PiP Mode';
});
