var mtvnPlayers = [];
var controller = new MTVNPlayerController('mtv_player','onPlayerLoaded'); 
var player; 
var videoPlaying

function mtvnPlayerLoaded( playerId ){
	//alert('mtvnPlayerLoaded '+playerId)
	mtvnPlayers['mtv_player']._onPlayerLoaded();
}
function MTVNPlayerController(id,onLoadFunctionName){
	// alert('MTVNPlayerController')
	mtvnPlayers[id] = this;
	this.onLoadFunctionName = onLoadFunctionName;
	this.playerLoaded = false;
	this.playerId = id;
	this.player = null;
	
	this._onPlayerLoaded = function(){
		// alert('this._onPlayerLoaded')
		this.player = (navigator.appName.indexOf("Microsoft") != -1) ? window[this.playerId] : document[this.playerId];
		this.playerLoaded = true;
		var f = eval(onLoadFunctionName);
		f(this);
	}
	
	this.onDump = function(){}
	
	this.dump = function(){
		var temp = "";
		if (this.playerLoaded){
			temp = this.player.getLogDump();
		}
		else{
			temp = "player not loaded";
		}
		this.onDump(temp);
	}
}

function onPlayerLoaded(controller){ 
   player = controller.player; 
   player.addEventListener('METADATA','onMetaData'); 
   player.addEventListener('STATE_CHANGE','onStateChange'); 
   player.addEventListener('NO_AD','onNoAd'); 

} 

function embedSnagged( blah ) {
	//alert("embedSnagged "+blah)
}

function onStateChange( state ) {
	
	//video started playing
	if(state == "initializing media") {
		videoPlaying = true;
		//recordPoints(1);
		trackVideoView();
		trackDL("View A Video");
	}
	
	//watched entire video
	//video was playing and then stopped (should only happen when video is complete)	
	if(state == "stopped" && videoPlaying) {
		//recordPoints(2);
		videoPlaying = false;
	}
}

function onMetaData( metadata ){ 
   //alert("Now watching: " + metadata.title); 
} 
function onNoAd( info ){ 
   // info.metadata 
   // info.adUrl 
   // info.counters 
}
