      /*
       * Chromeless player has no controls.
       */
      
      google.load("swfobject", "2.2");

      // Update a particular HTML element with a new value
      function updateHTML(elmId, value) {
        document.getElementById(elmId).innerHTML = value;
      }
      
      // This function is called when an error is thrown by the player
      function onPlayerError(errorCode) {
        //alert("An error occured of type:" + errorCode);
        alert("this video may be deleted.");
      }
      
      // This function is called when the player changes state
      function onPlayerStateChange(newState) {
        updateHTML("playerState", newState);
      }
      
      // Display information about the current state of the player
      function updatePlayerInfo() {
        // Also check that at least one function exists since when IE unloads the
        // page, it will destroy the SWF before clearing the interval.
        if(ytplayer && ytplayer.getDuration) {
          updateHTML("bytesloaded", ytplayer.getVideoBytesLoaded());
          updateHTML("bytestotal", ytplayer.getVideoBytesTotal());
          updateHTML("videoduration", ytplayer.getDuration());
          updateHTML("videotime", ytplayer.getCurrentTime());
          updateHTML("startbytes", ytplayer.getVideoStartBytes());
          updateHTML("volume", ytplayer.getVolume());
          /*
          updateHTML("videoDuration", ytplayer.getDuration());
          updateHTML("videoCurrentTime", ytplayer.getCurrentTime());
          updateHTML("bytesTotal", ytplayer.getVideoBytesTotal());
          updateHTML("startBytes", ytplayer.getVideoStartBytes());
          updateHTML("bytesLoaded", ytplayer.getVideoBytesLoaded());
          updateHTML("volume", ytplayer.getVolume());
          */
        }
         
          
        
      }
      
      // Allow the user to set the volume from 0-100
      function setVideoVolume() {
        var volume = parseInt(document.getElementById("volumeSetting").value);
        if(isNaN(volume) || volume < 0 || volume > 100) {
          alert("Please enter a valid volume between 0 and 100.");
        }
        else if(ytplayer){
          ytplayer.setVolume(volume);
        }
      }
      
      function play() {
        if (ytplayer) {
          ytplayer.playVideo();
        }
      }
      
      function pause() {
        if (ytplayer) {
          ytplayer.pauseVideo();
        }
      }
      
      function stop() {
         if (ytplayer) {
            ytplayer.stopVideo();
         }
      }
      
      function mute() {
        if(ytplayer) {
          ytplayer.mute();
        }
      }
      
      function unMute() {
        if(ytplayer) {
          ytplayer.unMute();
        }
      }
      function setVolume(newVolume) {
        if (ytplayer) {
          ytplayer.setVolume(newVolume);
        }
      }
      
      function seekTo(seconds) {
        if (ytplayer) {
          ytplayer.seekTo(seconds, true);
        }
      }
      
      // functions for the api calls
      function loadNewVideo(id, startSeconds) {
          if (ytplayer) {
              ytplayer.loadVideoById(id, startSeconds);
          }
      }
        
      // This function is automatically called by the player once it loads
      function onYouTubePlayerReady(playerId) {
        ytplayer = document.getElementById("ytPlayer");
        // This causes the updatePlayerInfo function to be called every 250ms to
        // get fresh data from the player
        setInterval(updatePlayerInfo, 250);
        updatePlayerInfo();
        ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
        ytplayer.addEventListener("onError", "onPlayerError");
        //Load an initial video into the player
        //ytplayer.cueVideoById("ylLzyHk54Z0");

		if (ytplayer) {
			var volume = parseInt(document.getElementById("volume").value);
          	if(isNaN(volume) || volume < 0 || volume > 100) {
          		ytplayer.setVolume(30);
        	}
		}
      }
      
      // The "main method" of this sample. Called when someone clicks "Run".
      function loadPlayer() {
        var yourDevKey = 'AI39si5AXdvyB_crRRWH1pT0Kp7JPeTS7PVQMnzLv8uU9Fqf8Qnt0hrgeZ_qzCkAWp4cFzB19zAOuugRwL5thFbXXU2plfRc6w';

        // Lets Flash from another domain call JavaScript
        var params = { allowScriptAccess: "always" };
        // The element id of the Flash embed
        var atts = { id: "ytPlayer" };
        // All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
        
        swfobject.embedSWF("http://www.youtube.com/apiplayer?key=" + yourDevKey +
                           "&enablejsapi=1&playerapiid=player1",
                           "ytapiplayer", "480", "295", "8", null, null, params, atts);

        // this sets the id of the object or embed tag to 'myytplayer'.
        // You then use this id to access the swf and make calls to the player's API
        //swfobject.embedSWF("http://gdata.youtube.com/apiplayer?key=" + yourDevKey + "&enablejsapi=1&playerapiid=ytplayer","ytapiplayer", "400", "300", "8", null, null, params, atts);

      }
      function _run() {
        loadPlayer();
      }
      google.setOnLoadCallback(_run);