	//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.
	//Version a3 - Dec 03, 2008 , code updated to track the clip end slightly before the clip ends to compensate for some videos not registering as not completed.  Changed percent base to 10000.
	//Version a4 - Dec 09, 2008 , code updated to include time out period required based off of a3 changes. 

	//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>=2500 && 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>=5000 && 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>=7500 && 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>=9990 && state==4)
  {
  state = 5
  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');
  timedVar();
  }        
}

	//Resets state after cool off period.
	function timedVar()
	{
	var Timer = parseInt(ytplayer.getDuration()*.9990);
	var t1=setTimeout("state='0'",Timer);
	}

	// Start create Percentage of Video.  Base is set to 10000.  i.e., 50% = 5000
    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()*10000)}
          }
        }
	// End create Percentage of Video