// Customized For Downelink
var mtvnPlayers = [];
LOGO = new Object();

LOGO.Player = new function(){
	this.controller;
	this.configParams = "mtvnPlayer%3Dlogo";
	this.playerMediaHost = "http://media.mtvnservices.com/";
	this.videoUri = null;
	
	this.instance;

	this.vid = null;
	this.id = null;
	this.autoPlay;
	this.adMode;
	this.fullEpisodeMode = false;
	this.coad = "coadTarget";
	this.disableCoad = false;
	this.playerTarget = "videoPlayer";
	
	this.coAdObject = null;
	
	this.jqueryEnabled = false;
	
	this.nextVideoUrl = null;
	
	this.allowCountdownSlate;
	
	
	var continuousPlayCookieName = "mtvnContinuousPlay";
	var continuousPlayConfigValue;
	var suspendContinuousPlay;

	
	this.init = function(){
		//console.log("LOGO.Player.init");
		LOGO.Player.setContinuousPlayConfigValue(true);	
	}

	
	this.setContinuousPlayConfigValue = function(val){
		continuousPlayConfigValue = true;
		//hardcoding to true
	}
	
	
	this.getContinuousPlayValue = function(){
		return LOGO.Player.getContinuousPlayConfigValue();
	}
	
	this.getContinuousPlayConfigValue = function(){
		return continuousPlayConfigValue;
	}

	
	this.getContinuousPlayOverride = function(){
		//console.log("LOGO.Player.getContinuousPlayValue("+LOGO.Player.getContinuousPlayValue()+")");
		return LOGO.Player.getContinuousPlayValue();
	}


	
	
	this.setCoad = function(adObject){
		if(LOGO.Player.disableCoad != true){
			//alert("set ad");
			var src = adObject.url;
			var w = adObject.width; 
			var h = adObject.height;
			var clickTag = adObject.clickUrl;
			
			var coadLoadTargetName = LOGO.Player.coad;
			
			if(w =="300" && h == "250"){
				if(document.getElementById(coadLoadTargetName+"_iframe") != null){
					document.getElementById(coadLoadTargetName).removeChild(document.getElementById(coadLoadTargetName+"_iframe"));
				}
				
				if(LOGO.Player.jqueryEnabled == true){
				 $(".prWrap").remove();	
				}
				
				var videoAdFrame = document.createElement("IFRAME");
				videoAdFrame.id = coadLoadTargetName+"_iframe";
				videoAdFrame.style.border='0px';
				videoAdFrame.src = src;
				videoAdFrame.width = "300";
				videoAdFrame.height = "250";
				videoAdFrame.scrolling = "no";
				videoAdFrame.allowtransparency = 'true';
				videoAdFrame.application="yes";
				document.getElementById(coadLoadTargetName).appendChild(videoAdFrame);
			}
		}
	}
	
	
	this.onPlayerLoaded = function(controller){
		if(LOGO.Player.disableCoad != true){
			LOGO.Player.controller.player.addEventListener("NO_AD","LOGO.Player.onNoAd");
		}
	}
	
	
	this.onNoAd = function (metadata){
		LOGO.Player.setCoAdObject(metadata.adUrl);
		LOGO.Player.refreshCoad();
	}
	
	
	this.setCoAdObject = function(adUrl){
		if(LOGO.Player.coAdObject == null){
			LOGO.Player.coAdObject = new Object();
		}
		LOGO.Player.coAdObject.url = adUrl.replace(/pfadx/, "adi").replace(/640x480/, "300x250").replace(/text\/xml/, "text/html");
		LOGO.Player.coAdObject.width = "300";
		LOGO.Player.coAdObject.height = "250";
		
		var newAdUrl = LOGO.Player.coAdObject.url;
		newAdUrl = newAdUrl.substring(0,newAdUrl.lastIndexOf("ord=")+4) + Math.round(Math.random()*Math.pow(10,7)).toString();
		
		LOGO.Player.coAdObject.url = newAdUrl;
			
	}
	
	
	this.refreshCoad = function(){
		LOGO.Player.setCoad(LOGO.Player.coAdObject);
	}
	
	
	this.addPlayer = function(){
		LOGO.Player.init();
		var configParams = null;
		configParams = "mtvnPlayer%3Dlogo";
		if(LOGO.Player.autoPlay == true){
			configParams = configParams+"%26autoPlay%3Dtrue";
		}
		
		if(LOGO.Player.allowCountdownSlate == true){
			configParams = configParams+"%26allowCountdownSlate%3Dtrue";
		}
		
		if(LOGO.Player.autoPlay == false){
			configParams = configParams+"%26autoPlay%3Dfalse";
		}
		if(LOGO.Player.id != null){
			configParams = configParams+"%26id%3D"+LOGO.Player.id;
		}
		
		if(LOGO.Player.fullEpisodeMode == true){
			configParams = configParams+"%26fullEpisodeMode%3Dtrue";
		} else {
			if(LOGO.Player.vid != null && LOGO.Player.vid != ""){
				configParams = configParams+"%26vid%3D"+LOGO.Player.vid;
			}
		}
		configParams = configParams+"%26adMode%3D"+LOGO.Player.adMode;
		LOGO.Player.configParams = null;
		LOGO.Player.configParams = configParams;
		
		if(LOGO.Player.videoUri != null){
			var flashVersion = "10.0.12.36";
	
			var embeddedPlayer = new SWFObject(LOGO.Player.playerMediaHost+LOGO.Player.videoUri,'embeddedPlayer', '100%', '100%', flashVersion, '#cccccc');
			embeddedPlayer.addVariable('configParams', LOGO.Player.configParams);
			embeddedPlayer.addParam("allowFullScreen",true);
			embeddedPlayer.addParam("name",embeddedPlayer);
			embeddedPlayer.addParam("id",embeddedPlayer);
			embeddedPlayer.addParam("enableJavascript",true);
			embeddedPlayer.addParam("wmode","transparent");
			embeddedPlayer.addParam("allowScriptAccess","always");
			embeddedPlayer.addParam("swliveconnect",true);
			embeddedPlayer.useExpressInstall('http://www.logoonline.com/player/expressInstall/adobeExpressInstall.swf');
			embeddedPlayer.write(LOGO.Player.playerTarget);
			
			LOGO.Player.controller = new MTVNPlayerController("embeddedPlayer","LOGO.Player.onPlayerLoaded");
		}
		
	}
	
	this.nextVideo = function(){
		if(LOGO.Player.nextVideoUrl != null &&  LOGO.Player.nextVideoUrl != ""){
			window.location.href = LOGO.Player.nextVideoUrl;
		}
	}

}

var mtvnSetCoad = LOGO.Player.setCoad;
var onPlayerLoaded = LOGO.Player.onPlayerLoaded;
//var playNextVideo = LOGO.Player.nextVideo;
