//console.log("onload functions");
//console.log(YouTubeVideos);

var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      
var ScriptedYTplayer;

function onYouTubeIframeAPIReady() {
  //console.log("YouTube API ready");
  if (YouTubeVideos.length>0) {
    var firstvid = YouTubeVideos[0];
    newPlayer(firstvid.container,firstvid.id); 
  }
}

function newPlayer(id,videoid) {
  //console.log("create new player");
  ScriptedYTplayer = new YT.Player(id, {
    height: '100%',
    width: '100%',
    videoId: videoid,
    events: {
      'onReady': onPlayerReady
    }
  });
}

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
  //console.log("player loaded");
  // event.target.playVideo();
}

function toggleMoreNav() {$('#morenav').slideToggle('slow');}
