// SCRIPTS FOR THE NEW AUDIO PLAYER 

(function(){

  function waitForIt(selector, time) {
    if(document.querySelector(selector)!=null) {

      var chat_title = document.getElementsByClassName("chatbox-title__text")[0];
      var element = document.createElement("span");

      element.innerHTML = '<audio id="player" preload="none" src="http://w-i-t-m.net:8001/radiodrama"></audio><div><button onclick="document.getElementById(\'player\').play()">Play</button><button onclick="document.getElementById(\'player\').pause();document.getElementById(\'player\').src=document.getElementById(\'player\').src;">Stop</button><button onclick="document.getElementById(\'player\').volume += 0.1">Vol +</button><button onclick="document.getElementById(\'player\').volume -= 0.1">Vol -</button></div>';

      chat_title.insertAdjacentElement('afterend', element);

      return;
    }
    else {
      setTimeout(function() {

        waitForIt(selector, time);

      }, time);
    }
  }

  waitForIt(".toggle-smiley", 1000);
})();

$(function() {
            console.log("PARENT READY");
            $("iframe").on("load", function(){
                console.log("LOADED");
                $(this).contents().find('.kiwi-startup-common').hide();
            });
        });


// SCRIPT for button to hide side pannel -->

  function fside() {
     var element = document.getElementById("side");
     element.classList.toggle("sideminclicked");
  }


// SCRIPT MOBILE SIDEMENU HIDE

  var x = window.matchMedia("(max-width: 768px)")

  function fsidemobile(x) {
      if (x.matches) { // If media query matches
      var element = document.getElementById("side");
       element.classList.toggle("sideminclicked");
      } else {
       element.classList.toggle("");
      }
    }

  fsidemobile(x) 


  function hideshowWelcome() {
     var elwel = document.getElementById("showWel");
     elwel.classList.toggle("hide");

     var bwel = document.getElementById("bhide_wel");
     bwel.classList.toggle("bhide_chat_off")

    we = document.getElementById("showWel");
    we.scrollIntoView();
  }

  function hideshowChat() {
     var elchat = document.getElementById("showChat");
     elchat.classList.toggle("hide");

     var bchat = document.getElementById("bhide_chat");
     bchat.classList.toggle("bhide_chat_off")

    cha = document.getElementById("showChat");
    cha.scrollIntoView();
  }

  function hideshowPad() {
    var elether = document.getElementById("showEther");
    elether.classList.toggle("hide");

    var bether = document.getElementById("bhide_ether");
    bether.classList.toggle("bhide_chat_off")

    eth = document.getElementById("showEther");
    eth.scrollIntoView();
  }


  function hideshowAudio() {
    var elau = document.getElementById("showAudio");
    elau.classList.toggle("hide");

    var bau = document.getElementById("bhide_au");
    bau.classList.toggle("bhide_chat_off")

    au = document.getElementById("showAudio");
    au.scrollIntoView();
  }



  function hideshowJitsi() {
    var eljit = document.getElementById("showJit");
    eljit.classList.toggle("hide");

    var bjit = document.getElementById("bhide_jit");
    bjit.classList.toggle("bhide_chat_off")

    jit = document.getElementById("showJit");
    jit.scrollIntoView();
  }


  function hideshowEssay() {
    var eless = document.getElementById("showEssay");
    eless.classList.toggle("hide");

    var bess = document.getElementById("bhide_ess");
    bess.classList.toggle("bhide_chat_off")

    ess = document.getElementById("showEssay");
    ess.scrollIntoView();
  }


  function hideshowVideo() {
    var elvid = document.getElementById("showVideo");
    elvid.classList.toggle("hide");

    var bvid = document.getElementById("bhide_vid");
    bvid.classList.toggle("bhide_chat_off")

    vid = document.getElementById("showVideo");
    vid.scrollIntoView();
  }



  function hideshowIMG() {
    var elimg = document.getElementById("showImg");
    elimg.classList.toggle("hide");

    var bimg = document.getElementById("bhide_img");
    bimg.classList.toggle("bhide_chat_off")

    im = document.getElementById("showImg");
    im.scrollIntoView();
  }



  function hideshowGal() {
    var elgal = document.getElementById("showGal");
    elgal.classList.toggle("hide");

    var bgal = document.getElementById("bhide_gal");
    bgal.classList.toggle("bhide_chat_off")

    gal = document.getElementById("showGal");
    gal.scrollIntoView();
  }


  // button while playing extra style

  function bplaytoggle () {
    var pbutton = document.getElementById("bp");
    pbutton.classList.add("bClicked");

    var sbutton = document.getElementById("bs");
    sbutton.classList.remove("bClicked");
  }


function bstoptoggle () {
    var pbutton = document.getElementById("bp");
    pbutton.classList.remove("bClicked");

    var sbutton = document.getElementById("bs");
    sbutton.classList.add("bClicked");
  }


  //  src="https://vjs.zencdn.net/7.10.2/video.min.js"

  // var player = videojs("#player");


  // var aud1= document.getElementById('audioBG');
  // var dur1= document.getElementById('dur1');
  // function mDur(dur,aud){dur.max= aud.duration};
  // function mPlay(dur,aud){dur.value=aud.currentTime};
  // function mSet(dur,aud){aud.currentTime=dur.value};


  // function playpause(podcast){
  // var myAudio = document.getElementById(podcast);
  // var myIcon = document.querySelector("."+podcast);
  // if (myAudio.paused) {
  // myIcon.className = podcast+" fa b-pause";
  // myAudio.play();
  // } else {
  // myIcon.className = podcast+" fa b-play";
  // myAudio.pause();
  // }
  // }