	//Version a1 - Code created by Michael C. Cook Nov 27, 2008. 
	//Version a2 - Dec 02, 2008 , updated code to listen more frequently to deal with rounding issue resulting on non-completed clip.  Removed alert.
	
	//Sets state to 0.  This allows us to detect plays
  state = 0;
  
  //Listener code from Google
      function onYouTubePlayerReady(playerId) {
          ytplayer = document.getElementById(cliptitle);
          setInterval(updateytplayerInfo, 50);
          updateytplayerInfo();
          ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
          }

	     function onytplayerStateChange(newState) {
          setytplayerState(newState);
        }

        function getPlayerState() {
          if (ytplayer) {
            return ytplayer.getPlayerState();
          }
        }
	//End listener code from Google       

  function updateytplayerInfo() {
  //WebTrends calling functions to track clip changes 
  percent = getPercent();
  pstate = getPlayerState();
 			
 	//If you would like to send fewer server requests, comments out the dcsMultiTrack calls for the data you do not want
 	//Checks to see if the clips is playing - Records data
 	if (pstate==1 && state<1)
  {
  state = 1
  dcsMultiTrack('DCS.dcsuri','/Video ' + cliptitle + ' Play','WT.ti','Video: ' + cliptitle + ' Play','WT.clip_t','You Tube Video','WT.clip_ev','v','WT.clip_n',cliptitle,'WT.dl','6');
   	}          
	
	//Checks to see if the clip is at 25%
  if (percent>=25 && state==1)
  {
  state = 2
  dcsMultiTrack('DCS.dcsuri','/Video ' + cliptitle + ' Play 25 percent','WT.ti','Video: ' + cliptitle + ' Play 25 percent','WT.clip_t','You Tube Video','WT.clip_ev','25','WT.clip_n',cliptitle,'WT.dl','6');
  	}          

	//Checks to see if the clip is at 50%
  if (percent>=50 && state==2)
  {
  state = 3
  dcsMultiTrack('DCS.dcsuri','/Video ' + cliptitle + ' Play 50 percent','WT.ti','Video: ' + cliptitle + ' Play 50 percent','WT.clip_t','You Tube Video','WT.clip_ev','50','WT.clip_n',cliptitle,'WT.dl','6');
  }                   

	//Checks to see if the clip is at 75%
	if (percent>=75 && state==3)
  {
  state = 4
  	dcsMultiTrack('DCS.dcsuri','/Video ' + cliptitle + ' Play 75 percent','WT.ti','Video: ' + cliptitle + ' Play 75 percent','WT.clip_t','You Tube Video','WT.clip_ev','75','WT.clip_n',cliptitle,'WT.dl','6');
  	}        

	//Checks to see if the clip is complete. If so allows for recording of additional views
	if (percent==100 && state==4)
  {
  state = 0
  dcsMultiTrack('DCS.dcsuri','/Video ' + cliptitle + ' Finish','WT.ti','Video: ' + cliptitle + ' Finish','WT.clip_t','You Tube Video','WT.clip_ev','f','WT.clip_n',cliptitle,'WT.dl','6');
  }        
}

// Start create Percentage of Video
    function getPercent() {
          if (ytplayer) {
// Returns 0% if the player hasn't started yet to avoid reporting error
        if (ytplayer.getCurrentTime() <= 0)
   {return 0}
   else
   {return parseInt(ytplayer.getCurrentTime() / ytplayer.getDuration()*100)}
          }
        }
// End create Percentage of Video