
var player = null;

function play_video(ytid)
{
	console.log('play_video feawf: ' + ytid);
	if(player == null)
	{
		player = new YT.Player('ytvideo', {
			height: '417',
			width: '742',
			videoId: ytid,
			playerVars: {
				origin: 'https://okorchestra.org/',
				enablejsapi: 1,
				rel: 0,
				showinfo: 0
			},
			events: {
			'onReady': onPlayerReady,
			'onStateChange': onPlayerStateChange
		}});
	}
	else
	{
		player.loadVideoById({
			'videoId': ytid
		});
	}
}

function onYouTubeIframeAPIReady()
{
	console.log("API Ready");
	// player = new YT.Player('ytvideo', {
	// 	height: '390',
	// 	width: '640',
	// 	videoId: 'ytid' ?>,
	// 	events: {
	// 	'onReady': onPlayerReady,
	// 	'onStateChange': onPlayerStateChange
	// }});
}

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event)
{
	event.target.playVideo();
}


function onPlayerStateChange(event)
{
	if(event.data == -1) // unstarted
	{
		
	}
	else if(event.data == 0) // unstarted
	{
		
	}
	else if(event.data == 1) // playing
	{
		
	}
	else if(event.data == 2) // paused
	{
		
	}
	else if(event.data == 3) // buffering
	{
		
	}
	else if(event.data == 5) // video cued
	{
		
	}
}

$(document).ready(function(){
	$('.video').click(function(){
		$(this).addClass('active');
		$(this).siblings().removeClass('active');
	});
	
	console.log("yep");
	
	var tag = document.createElement('script');

	tag.src = "https://www.youtube.com/iframe_api";
	var firstScriptTag = document.getElementsByTagName('script')[0];
	console.log(firstScriptTag);
	firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

	// 3. This function creates an <iframe> (and YouTube player)
	//    after the API code downloads.
	
});