
function CheckPlay() {
if(document.getElementById("hidPlayerReady").value == 1) {
if(document.getElementById("hid_YTplayer_On").value == 0)
	{
	loadNewVideo();
	}
	else
	{
	play();
	}
}
}
        function onYouTubePlayerReady(playerId) {
		  document.getElementById("hidPlayerReady").value = 1
          ytplayer = document.getElementById("myytplayer");
		 cueNewVideo(document.getElementById('hid_VID_ID').value, 0);
          setInterval(updateytplayerInfo, 250);
          updateytplayerInfo();
          ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
        }

        function onytplayerStateChange(newState) {
          setytplayerState(newState);
        }

        // functions for the api calls
        function loadNewVideo() {
		var id = document.getElementById("hid_VID_ID").value
		var startSeconds = 0
          if (ytplayer) {
            ytplayer.loadVideoById(id, parseInt(startSeconds));
			document.getElementById("hid_YTplayer_On").value = 1
          }
        }

        function cueNewVideo(id, startSeconds) {
          if (ytplayer) {
            ytplayer.cueVideoById(id, startSeconds);
          }
        }

        function play() {
          if (ytplayer) {
            ytplayer.playVideo();
          }
        }

        function pause() {
          if (ytplayer) {
            ytplayer.pauseVideo();
          }
        }

        function stop() {
          if (ytplayer) {
            ytplayer.stopVideo();
			document.getElementById("hid_YTplayer_On").value = 0
          }
        }


        function mute() {
          if (ytplayer) {
            ytplayer.mute();
          }
        }

        function unMute() {
          if (ytplayer) {
            ytplayer.unMute();
          }
        }

        function getVideoUrl() {
          alert(ytplayer.getVideoUrl());
        }

        function clearVideo() {
          if (ytplayer) {
            ytplayer.clearVideo();
          }
        } 
		
		
	function SetToplay() {
  	if (ytplayer) {
    cueNewVideo(document.getElementById('hid_VID_ID').value, 0);
  	}
	}
		
function ChangeVideo(VidToStart)
{	
if(document.getElementById("hidPlayerReady").value == 1) {
stop();
document.getElementById("hid_YTplayer_On").value = 0;
document.getElementById("hid_VID_ID").value = VidToStart;
CheckPlay();
}
}
function ShowHideLayer(boxID,ClassRAW) {

var RawInstanceID = boxID.id

	/* If the selected box is currently invisible, show it */
	if(document.getElementById(ChangeDIV).style.display == "block" || document.getElementById(ChangeDIV).style.display ==""){
		document.getElementById(ChangeDIV).style.display = "none";
	}
	/* otherwise hide it */
	else {
		document.getElementById(ChangeDIV).style.display = "block";
	}
}