/*
*	To send WebTrends information by JavaScript from user actions on Longtail Video Flash Player
*	
*	Currently: PLAY, PAUSE, END
*
*	Originally created December 2009 by Drummond Pearson
*	THIS CODE NEEDS THE NORMAL WEBTRENDS SCRIPT AT THE BOTTOM OF THE HTML PAGE
*	AS WELL AS THIS SCRIPT FILE, OR ELSE THE WEBTRENDS INFO WILL NOT SEND
*/
//====================================================================================//

// create varisbles
var currentState = "NONE"; 
var previousState = "NONE"; 
var playerState;
var player = null; 

// test player is ready and reference addListeners function
function playerReady(thePlayer) { player = document[thePlayer.id];
addListeners(); }

// start listening for player actions
function addListeners() {
	if (player) { 
		player.addModelListener("STATE", "stateListener");
	} else {
		setTimeout("addListeners()",100);
	}
}
	
// to receive, translate and send the player actions
function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate; 
	
	if ((currentState == "PLAYING")&&(previousState == "BUFFERING")) {
		playerState = 'Play'; 
	}
	if ((currentState == "PLAYING")&&(previousState == "PAUSED")) {
		playerState = 'Play'; 
	}
	if ((currentState == "PAUSED")&&(previousState == "PLAYING")) {
		playerState = 'Pause';
	}
	if ((currentState == "IDLE")&&(previousState == "PLAYING")) {
		playerState = 'End'; 
	}
	//alert(playerState);
	if ((playerState != undefined)){
			//alert(playerState);
			//dcsMultiTrack('DCS.dcsuri',document.location.href,'WT.ti',document.title+playerState);
			dcsMultiTrack('DCS.dcsuri',document.location.href,'WT.ti',document.title+'%20'+playerState,'WT.si_n','MoviePlayer','WT.si_p',playerState);
			//alert('DCS.dcsuri'+'-'+document.location.href+' '+'WT.ti'+'-'+document.title+'%20'+playerState+' '+'WT.si_n'+'-'+'MoviePlayer'+' '+'WT.si_p'+'-'+playerState);
	}
}
