    function updateHTML(elmId, value) {
      document.getElementById(elmId).innerHTML = value;
    }

    function setytplayerState(newState) {
      updateHTML("playerstate", newState);
    }

    function onYouTubePlayerReady(playerId)
	{
      ytplayer = document.getElementById(playerId);
	  ytplayer.mute();	  
	  ytplayer.loadVideoById(yt_items[n].video, 5);
      ytplayer.addEventListener("onError", "onPlayerError");
      ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
      setInterval(updateytplayerInfo, 1000);
      updateytplayerInfo();
    }

    function onPlayerError(errorCode) {
	  	loadNewVideo(yt_items, 0);
    }

    function onytplayerStateChange(newState)
	{
		if (newState == 0) {
			updateytplayerInfo();
		}
		else if(newState == 1)
		{
			updateHTML("movie_title", "<a href=\"" + _url + yt_items[n].video +"/\">" + yt_items[n].title +"</a>");
		}
    }

    function updateytplayerInfo() {
	  if (getCurrentTime() > 15 || ytplayer.getPlayerState() == 0) {
	  	loadNewVideo(yt_items, 0);
	  }
    }

    function loadNewVideo(yt_items, startSeconds) {
      if (ytplayer) {
		n += 1;
	  	if (yt_items.length == n || yt_items.length < n)
		{
			n=0;
	  	}
        ytplayer.loadVideoById(yt_items[n].video, parseInt(startSeconds));
		updateHTML("movie_title", "<a href=\"" + _url + yt_items[n].video +"/\">" + yt_items[n].title +"</a>");
      }
    }

   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();
      }
    }

    function getPlayerState() {
      if (ytplayer) {
        return ytplayer.getPlayerState();
      }
    }

    function seekTo(seconds) {
      if (ytplayer) {
        ytplayer.seekTo(seconds, true);
      }
    }

    function getBytesLoaded() {
      if (ytplayer) {
        return ytplayer.getVideoBytesLoaded();
      }
    }

    function getBytesTotal() {
      if (ytplayer) {
        return ytplayer.getVideoBytesTotal();
      }
    }

    function getCurrentTime() {
      if (ytplayer) {
        return ytplayer.getCurrentTime();
      }
    }

    function getDuration() {
      if (ytplayer) {
        return ytplayer.getDuration();
      }
    }

    function getStartBytes() {
      if (ytplayer) {
        return ytplayer.getVideoStartBytes();
      }
    }

    function mute() {
      if (ytplayer) {
        ytplayer.mute();
      }
    }

    function unMute() {
      if (ytplayer) {
        ytplayer.unMute();
      }
    }
    
    function getEmbedCode() {
      alert(ytplayer.getVideoEmbedCode());
    }

    function getVideoUrl() {
      alert(ytplayer.getVideoUrl());
    }
    
    function setVolume(newVolume) {
      if (ytplayer) {
        ytplayer.setVolume(newVolume);
      }
    }

    function getVolume() {
      if (ytplayer) {
        return ytplayer.getVolume();
      }
    }

    function clearVideo() {
      if (ytplayer) {
        ytplayer.clearVideo();
      }
    }