/*
	YouTube Javascript Video Controller
	by Floris ten Hove - Floris ten Hove Internetdiensten
	Copyright 2009
*/

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById('myytplayer');
  ytplayer.unMute();
  /*
  //autoplay
  loadNewVideo('JMfBW3rUSl8',0);
  ytplayer.unMute();
  */
}

function play() {
  if (ytplayer) 
  {
    ytplayer.playVideo();
  }
}

function pause() {
  if (ytplayer) {
	ytplayer.pauseVideo();
  }
}

function stop() {
  if (ytplayer) {
	ytplayer.stopVideo();
  }
}

function toggleMute(el) {
	if (ytplayer) {
		if (ytplayer.isMuted()) {
			ytplayer.unMute();
			//if (el) el.className = 'unmuted';
			el.style.backgroundImage="url('inc/image/btn-unmuted.gif')";
		}
		else {
			ytplayer.mute()
			//if (el) el.className = 'muted';
			el.style.backgroundImage="url('inc/image/btn-muted.gif')";
		}
	}
}

function togglePlay(el, movieId) {
	if (ytplayer) {
		if ( (ytplayer.getPlayerState() !== 1) && (ytplayer.getPlayerState() !== 2) && (ytplayer.getPlayerState() !== 3) )
		{
			loadNewVideo(movieId, 0);
		}
		
		if (ytplayer.getPlayerState() != 1) {
			this.play();
			if (el)
			{
				el.style.backgroundImage="url('inc/image/btn-pause.gif')";

			}
		}
		else if (ytplayer.getPlayerState() != 2) {
			this.pause();
			if (el)
			{
				el.style.backgroundImage="url('inc/image/btn-play.gif')";
			}
		}
	}
}

function togglePlayNew(el, movieId) 
{
	if (ytplayer) {
		loadNewVideo(movieId, 0);
		
		if (ytplayer.getPlayerState() != 1) 
		{
			this.play();
			if (el)
			{
				el.style.backgroundImage="url('inc/image/btn-pause.gif')";
			}
		}
		else if (ytplayer.getPlayerState() != 2) 
		{
			this.pause();
			if (el)
			{
				el.style.backgroundImage="url('inc/image/btn-play.gif')";
			}
		}
	}
}

function loadNewVideo(id, startSeconds) {
  if (ytplayer) {
	ytplayer.loadVideoById(id, startSeconds);
  }
}