var ytplayer=null;
var so=null;
var params = { allowScriptAccess: "always", bgcolor: "#ffffff" , allowFullScreen: "true"};
var atts = { id: "myytplayer" };


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

        function onytplayerStateChange(newState) {
          	//setytplayerState(newState);
		//alert(newState);
		if(newState=="1"){
//			alert(ytplayer.getVideoURL());
//			alert(ytplayer.getID());
		}
        }

        function updateytplayerInfo() {
          updateHTML("bytesloaded", getBytesLoaded());
          updateHTML("bytestotal", getBytesTotal());
          updateHTML("videoduration", getDuration());
          updateHTML("videotime", getCurrentTime());
          updateHTML("startbytes", getStartBytes());
          updateHTML("volume", getVolume());
        }

        // functions for the api calls
        function loadNewVideo(id, startSeconds) {
  		if(!!!ytplayer){
			so=swfobject.embedSWF("http://www.youtube.com/v/"+id+"&enablejsapi=1&autoplay=0&playerapiid=ytplayer","ytapiplayer", "300", "245", "8", null, null, params, atts);
		}else{
			so=swfobject.embedSWF("http://www.youtube.com/v/"+id+"&enablejsapi=1&autoplay=1&playerapiid=ytplayer",ytplayer.id, "300", "245", "8", null, null, params, atts);
		}
//	 	$("title_view").innerHTML=VideoTitle[VideoID];
	/*if(!!ytplayer){
		alert(id);
           	ytplayer.loadVideoById(id, startSeconds);
          }*/
		return false;
        }

        function cueNewVideo(id, startSeconds) {
          if (ytplayer) {
            ytplayer.cueVideoById(id, startSeconds);
          }
        }

        function play() {
          if(ytplayer) {
            ytplayer.playVideo();
	    //$("title_view").innerHTML=VideoTitle[VideoID];
          }
        }

        function pause() {
          if (ytplayer) {
            ytplayer.pauseVideo();
          }
        }

        function stop() {
          if (ytplayer) {
            ytplayer.stopVideo();
	//		$("title_view").innerHTML="";
          }
        }

        function getPlayerState() {
          if (ytplayer) {
            return ytplayer.getState();
          }
        }

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

