
      google.load("swfobject", "2.1");
  
 

        function updateHTML(elmId, value) {
          document.getElementById(elmId).innerHTML = value;
        }

        function setytplayerState(newState) {
          updateHTML("playerstate", newState);
        }

        function onYouTubePlayerReady(playerId) {
          ytplayer = document.getElementById("myytplayer");
          setInterval(updateytplayerInfo, 250);
          updateytplayerInfo();
          ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
          ytplayer.addEventListener("onError", "onPlayerError");
          
          if ($("body").attr("id") == "Home") {
              loadRandomVideo();
          }
          else{
              loadNewVideo(document.getElementById('loadvideoid').value, document.getElementById('startseconds').value);   
          }         
        }    

        function onytplayerStateChange(newState) {
           //setytplayerState(newState);
        
           if (newState==0 && $("body").attr("id") == "Home") {
                   loadRandomVideo();             
           }

           if (newState==0 && $("body").attr("id") == "FunGames") {
                   $('#video_object').hide();
                   pause();
                   $('#video_screen').show();
           }
        }

        function loadRandomVideo() {
            //setytplayerState(newState);

            var randomNum = Math.ceil(Math.random()*6);
            var i = 0;

            $( "input.loadvideo" ).each( function() {
                 i++;
                 if (randomNum == i){
                    video_id = $( this ).attr( "id" );

                    //highlight active button
                    for(i2 = 1; i2 < 7; i2++){
                       $("#video_img_"+i2).attr("src", "wp-content/themes/bb_home/images/"+i2+".jpg");
                    }
                    $("#video_img_"+i).attr("src", "wp-content/themes/bb_home/images/"+i+"a.jpg");

                    //load random video
                    loadNewVideo(document.getElementById(video_id).value, document.getElementById('startseconds').value);

                 }
            } );

        }

        function onPlayerError(errorCode) {
          //alert("An error occured: " + errorCode);
        }

        function updateytplayerInfo() {
          
        }

        // functions for the api calls
        function loadNewVideo(id, startSeconds) {
          if (ytplayer) {
            ytplayer.loadVideoById(id, parseInt(startSeconds));
          }
        }

        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();
          }
        }
