/********************************************************/
/********************* LISTSET MANAGER ******************/
/********************************************************/

// Deletes a list
MTVN_PL.ListSetManager.deleteList = function (listID, widgetID, name) {
	name = unescape(name);
	var message = MTVM.lang.playlist.areYouSure+' <br /><b>"'+name+'"</b>?';
	var evtObj = { listID : listID, _widgetID : widgetID };
	MTVN_PL.DialogManager.showConfirmDialog ('Delete List', 
											  message, 
											  MTVM.lang.playlist.yes, 
											  MTVM.lang.playlist.no, 
											  undefined, 
											  MTVN_PL.Controller.deleteList, 
											  evtObj, 
											  MTVN_PL.Controller);

}



/********************************************************/
/********************* BASE PLAYLIST ********************/
/********************************************************/


/*** Title of the widget ***/
MTVN_PL.BasePlaylist.prototype.truncateLength = 15;
MTVN_PL.BasePlaylist.prototype._genTitle = function (title) {
	var str = "";
	
	truncatedTitle	= MTVM.util.truncateString(title, this.truncateLength);
	escapedTitle	= MTVM.util.escapeQuotes(title);	
	
	str += "<span class=\"MTVN_PL-title\" title=\""+escapedTitle+"\" id=\"MTVN_PL_"+this.containerID+"_"+this.widgetID+"_title\">";	
	str += MTVM.util.escapeQuotes(truncatedTitle);
	str += "</span>";
	return str;
}



// MK : Private methods shouldn't be overloaded. 
// If there's a reason for this then let's talk and we can figure out an alternative
/*MTVN_PL.BasePlaylist.prototype._genItemContainer = function (item, position) {
	// skip if bad data
	if (MTVN_PL.util.isEmpty(item.data)) return '';
	
	var str = '';
	str += '<div class="MTVN_PL-item'+((position + 1) % 2 == 0 ? '' : ' MTVN_PL-oddrow')+'" mgid="'+item.mgid+'" ' +
		'id="MTVN_PL_'+MTVN_PL.util.sanitize(item.unique_id)+
		'_item_'+MTVN_PL.util.sanitize(this.widgetID)+
		'" onmouseover="MTVM.Playlist.swapItemClass(this, \'over\', \''+item.mgid+'\');" onmouseout="MTVM.Playlist.swapItemClass(this, \'out\', \''+item.mgid+'\');">';
	str += this.genItemContents(item, position);
	str +='<div style="clear:both" /></div>';
	str += '</div>';
	return str;
}*/

MTVN_PL.BasePlaylist.prototype.genMessageSlate = function() {return "";}


MTVN_PL.BasePlaylist.prototype.genEmptySlateContents = function (playlist) {
	str = '';
	str += '<div class="listEmptyHeader">'+MTVM.lang.playlist.listEmpty+'.</div>';
	//str += '<div class="listEmptyBody">'+MTVM.lang.playlist.clickThe+' <span class="MTVN_PL-addButton-button"></span> '+MTVM.lang.playlist.buttonAdd+' <br/><br/> <a href="'+MTVM.config.fluxCommunityUrl+'/'+MTVM.lang.urls.charts+'">'+MTVM.lang.playlist.browseVideo+'</a> '+MTVM.lang.playlist.startAdding+'</div>';
	str += '<div class="listEmptyBody">'+MTVM.lang.playlist.clickThe+' <span class="MTVN_PL-addButton-button"></span> '+MTVM.lang.playlist.buttonAdd+' <br/><br/> <a href="/'+MTVM.lang.urls.featured+'/just_added/'+MTVM.config.featuredDreIds.firstCol+'">'+MTVM.lang.playlist.browseVideo+'</a> '+MTVM.lang.playlist.startAdding+'</div>';
	
	str += '<div class="listEmptyFooter"></div>';
	return str;
}


MTVN_PL.BasePlaylist.prototype.genHeaderContents = function (playlist) {
	var ad = MTVM.Playlist.getSponsorLogo("playback");	
	var cssClass = MTVM.config.languageCode + "-" +MTVM.config.countryCode;
	if(typeof ad !="undefined" && ad != null && ad !="" && ad !="null")
	{
		ad = ad;
	}
	else
	{
		ad ="";
	}
	
	var str = "<div class=\"MTVN_PL-titleWrapper\"><div class=\"MTVN_PL-title left\">"+this._genTitle(playlist.name)+" </div>";
	str += " <div class=\"MTVN_PL-totalItems left\">(" + playlist.contentList.length + ")</div>";
	str += " <div class=\"right MTVN_PL-sponsorLogo\">"+ad+"</div>";
	str += " <div class=\"clear\"></div></div>";
	
	return str;
}




// *** Generates HTML for the list footer
MTVN_PL.BasePlaylist.prototype.genFooterContents = function (playlist) {
	
	str = '';
	str += '<div class="MTVN_PL-button-group">';
	
	var state = playlist.itemCount > 0 ? '' : 'disabled';
	
	if (playlist.user.isCurrentUser) {
		str += this.genListEditButton({ buttonTxt : MTVM.Playlist.Buttons.getEditButton({state:state, style:"dark"})});
	}
	str += this.genListShareButton({ buttonTxt : MTVM.Playlist.Buttons.getShareButton({state:state, style:"dark"}), playlist : playlist });
	str += '</div>';
	return str;
}



/********************************************************/
/********************* PLAYBACK PLAYLIST ****************/
/********************************************************/

MTVN_PL.PlaybackPlaylist.prototype.genItemContents = function (item, position) {
	
	var playOnClick = 'MTVN_PL.BasePlaylist.prototype.playAction(\''+item.mgid+'\', \''+this.listID+'\', \''+this.widgetID+'\', \''+ item.unique_id + '\')';
	str = '';
	str += '<div class="MTVN_PL-list-click-overlay" onclick="'+playOnClick+'">';
	str += this.genItemNum(item, position);	
	str += MTVN_PL.PlaybackPlaylist.superproto.genItemContents.call(this, item, position);
	str += '<div class="MTVN_PL-play-text" id="play_'+MTVN_PL.util.sanitize(this.widgetID)+'"><div style="width:100px;"><img src="/sitewide/img/playlist/arrowGreen.gif" height="8" width="8" border="0"/> ' +
	unescape(MTVN_PL.dictionary.phrases.NowPlaying) + '</div></div>';
	str += '</div>';
	return str;	
}




/********************************************************/
/********************* EDIT PLAYLIST ********************/
/********************************************************/
MTVN_PL.EditPlaylist.prototype.truncateLength = 35;


MTVN_PL.EditPlaylist.prototype.genHeaderColumns = function () {	
	var str="";
	str += '<div class="MTVN_PL-columnHeader">'+	
	'<div class="MTVN_PL-columnHeader-order">'+MTVM.lang.playlist.order+'</div>'+
	'<div class="MTVN_PL-columnHeader-thumb"><img src="/sitewide/img/spacer.gif"/></div>'+
	'<div class="MTVN_PL-columnHeader-title">'+MTVM.lang.playlist.titleAndArtist+'</div>'+
	'<div class="MTVN_PL-columnHeader-delete">'+MTVM.lang.playlist.deleteIt+'</div>'+
	'<div style="clear:both;"></div>'+
	'</div>';
	return str;	
}


MTVN_PL.EditPlaylist.prototype.render = function (playlist) {
	MTVN_PL.debug('rendering widget: ' + this.listID, 'BasePlaylist.render');
	
	this.playlist = playlist;
	
	var str = this._genHeader(playlist);
	str += this.genHeaderColumns();
	str += this._genItemSet(playlist);
	str += this._genFooter(playlist);
	return str;
}


MTVN_PL.EditPlaylist.prototype.genThumbnail = function (item, imgUrl) {
	return '<div class="MTVN_PL-thumbnail"><img src="' + imgUrl + '" /></div>';
}



// *** Generates the html within the footer
MTVN_PL.EditPlaylist.prototype.genFooterContents = function (playlist) {
	str ='';
	str += '<div class="MTVN_PL-button-group">';
	
	if(playlist.contentList.length>0){

		str += this.genListPlayButton ({ buttonTxt : MTVM.Playlist.Buttons.getPlayAllButton()});
		str += this.genListEditButton({ buttonTxt : MTVM.Playlist.Buttons.getRenameButton()});
		str += this.genListShareButton({ buttonTxt : MTVM.Playlist.Buttons.getShareButton({state:'default', style:"white"}), playlist : playlist });
	}

	str +="</div>";
	return str;
}


// *** Generates the delete button for an item
MTVN_PL.EditPlaylist.prototype.genDeleteButton = function (item) {
	var str = '';
	str += '<div style="float:right; margin-top:-5px;">';
	str += '<a href="javascript://" class="MTVN_PL-deleteButton" onclick="MTVN_PL.EditPlaylist.prototype._onDeleteClicked(\''+this.listID+'\', \''+item.unique_id+'\', \''+this.widgetID+'\'); return false"></a>';
	str += '</div>';
	return str;
}



// MK: the EditQuicklist widget has linked thumbnails and titles, yet this one doesn't--
// Is that an oversight? If it is I believe the quicklist widget inherits from this widget 
// so setting the onclick events here will kill two birds with one stone. See the genThumbnail 
// and genTitle methods on the EditQuicklist to see how to generate the new onclick events
MTVN_PL.EditPlaylist.prototype.genThumbnail = function (item, imgUrl) {
	//var playOnClick = 'MTVN_PL.EditPlaylist.prototype.playAction(\''+this.listID+'\', \''+item.mgid+'\')';	
	return '<div class="MTVN_PL-thumbnail"><img src="' + imgUrl + '" /></div>';
}

MTVN_PL.EditPlaylist.prototype.genTitle = function (item, title) {
	//var playOnClick = 'MTVN_PL.EditPlaylist.prototype.playAction(\''+this.listID+'\', \''+item.mgid+'\', \''+this.widgetID+'\', \''+ item.unique_id + '\')';
	return '<span class="MTVN_PL-itemTitle">'+title+'</span><br />';	
}




/********************************************************/
/********************* EDIT LISTSET *********************/
/********************************************************/



MTVN_PL.EditListSet.prototype.genListContents = function (playlist) {
	var str = '';
	str = '<div class="MTVN_PL-listset-thumb">';
	str += this.genListThumbnailContents(playlist);
	str += '</div>';
	str += '<div class="MTVN_PL-listset-details">';
	str += this.genListDetails(playlist);
	
	str += '<div class="MTVN_PL-button-group">';
	str += this.genListEditButton({ listID : playlist.contentURI, buttonTxt : MTVM.Playlist.Buttons.getEditButton({state:'default', style:'white'}) });
	str += this.genListShareButton({ buttonTxt : MTVM.Playlist.Buttons.getShareButton({state:'default', style:'white'}), playlist : playlist });
	str += '</div>';
	
	str += '</div>';
	
	playlistName = escape(playlist.name);
	str += "<div class=\"MTVN_PL_listset-deleteButtonWrapper\"><a class=\"MTVN_PL-deleteButton\" href=\"javascript://\" onclick=\"MTVN_PL.ListSetManager.deleteList('"+playlist.contentURI+"', '"+this.widgetID+"', '"+playlistName+"'); return false;\"></a></div>";
	
	return str;
}



MTVN_PL.EditListSet.prototype.genFooterContents = function (listSet) {
	
	var str = "";
	str = '<div class="right MTVN_PL-listset-footer">'+this.genListCreateButton({buttonTxt : MTVM.Playlist.Buttons.getNewPlaylistButton()})+'</div><div class="clear"></div>';

	if(listSet.length<1)
	{
		str = "<div class=\"MTVN_PL-listset-footer-emptyListset\">"+MTVM.lang.playlist.dontHave+"</div>" + str;
	}
	return str;
}





/********************************************************/
/********************* VIDEO HELPER *********************/
/********************************************************/


MTVN_PL.VideoHelper.onPlayerLoaded = function(controller) {
	MTVN_PL.VideoHelper.player = controller.player;
	MTVN_PL.VideoHelper.player.addEventListener('STATE_CHANGE','MTVN_PL.VideoHelper.onStateChange');
	MTVN_PL.VideoHelper.player.addEventListener("METADATA","MTVN_PL.VideoHelper.onMetaData");
	
	MTVN_PL.VideoHelper.player.addEventListener('NO_AD','MTVM.player.onNoAd');
}


function resizePlayer(w,h){
	var playerWrap = document.getElementById(vidContainer);        
	playerWrap.style.width = w + 'px';        
	playerWrap.style.height = h + 'px';    
}
					

function mtvnSetCoad(adObject){
     var coad = document.getElementById('coadFrame');
     coad.src=adObject.url;
     coad.style.width=adObject.width+'px';
     coad.style.height=adObject.height+'px';
}	

function getQueryValue(name) {  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp(regexS);  
	var results = regex.exec(window.location.href);  
	if(results == null)    
		return "";  
	else    
		return results[1];
}

function silentErrorHandler() {return true;}
//window.onerror=silentErrorHandler;



MTVN_PL.VideoHelper.onPlay = function (eventObj, requestArgs) 
{	
	var el = document.getElementById('MTVN_PL-video-player');
	switch(MTVM.config.countryCode)
	{
		case "us":
			MTVN_PL.VideoHelper.domesticPlayer(eventObj, requestArgs, el);
			break;
			
		default:
			MTVN_PL.VideoHelper.internationalPlayer(eventObj, requestArgs, el);
			break;
	}
}

MTVN_PL.VideoHelper.domesticPlayer = function(eventObj, requestArgs, el)
{	
	el.innerHTML = 
		'<object height="'+MTVM.config.swfPlayer.height+'" width="660" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="player1">'+
		'<param value="always" name="allowScriptAccess"/>'+
		'<param value="true" name="allowFullScreen"/>'+
		'<param value="transparent" name="wmode"/>'+
		'<param value="'+MTVM.config.mtvnservicesURL+'/'+eventObj.contentURI+'" name="movie"/>'+		
		'<param value="autoPlay=true&amp;configParams=playMode%3DuserPlaylist%26psp%3D0%26playlistType%3D'+MTVM.Playlist.getPlaylistType()+'%26playlistTitle%3D'+MTVN_PL.VideoHelper.flattenUGCTitle(MTVM.Playlist.getPlaylistName())+'" name="flashvars" />'+
		'<embed height="'+MTVM.config.swfPlayer.height+'" width="660" allowscriptaccess="always" allowfullscreen="true" '+
		' wmode="transparent" '+
		'flashvars="autoPlay=true&amp;configParams=playMode%3DuserPlaylist%26psp%3D0%26playlistType%3D'+MTVM.Playlist.getPlaylistType()+'%26playlistTitle%3D'+MTVN_PL.VideoHelper.flattenUGCTitle(MTVM.Playlist.getPlaylistName())+'" '+
		'type="application/x-shockwave-flash" name="player1" id="player1" src="'+MTVM.config.mtvnservicesURL+'/'+eventObj.contentURI+'"/>'+
		'</object>';	
	MTVN_PL.VideoHelper.controller = new MTVNPlayerController('player1','MTVN_PL.VideoHelper.onPlayerLoaded');
}

MTVN_PL.VideoHelper.internationalPlayer = function(eventObj, requestArgs, el)
{
	var uri = eventObj.contentURI;
	window.configUrl = "";
	
	/*var flashVars = 'CONFIG_URL=http://intl.esperanto.mtvi.com/player/configuration.jhtml%3Fads%3Dtrue%26uri%3D' +
		eventObj.contentURI +
		'%26css%3D%26full%3Dfalse%26autoPlay%3Dfalse%26continuousPlay%3Dfalse%26sitePath%3D' +
		document.location +
		'%26resize%3DfullOnly%26screenMode%3Dwide%26getUrl%3Dtrue%26defaultLang%3D' +
		'en_UK' +
		'%26jsMode%3Dfalse%26embed%3Dtrue%26isLive%3Dfalse%26moreVideos%3Dfalse%26endSlate%3Dfalse%26version%3D%26subtitles%3Dfalse%26playerQuery%3D%26'+
		'autoplay%3dtrue%26playMode%3DuserPlaylist%26psp%3D0%26playlistType%3D'+MTVM.Playlist.getPlaylistType()+'%26playlistTitle%3D'+MTVN_PL.VideoHelper.flattenUGCTitle(MTVM.Playlist.getPlaylistName());
	*/

    //vidContainer = name of div that loads the player
    //fullEpisode =  true|false - default false
    //autoPlay = true|false - default site config value gets used
    //continuousPlay = true|false - default site config value gets used
    //uri = can set uri, will be overwritten by query uri
    //defaultSize = small|medium|large - default medium
    //screenMode =  normal|wide - default normal
    //sizeOverride = true|false - default false; uses specified vidContainer size if set to true
    //getUrl = true|false - default true - turns on getUrl menu					
				
    
    
    //************ GMP BLOCK *****************//
	
	// if vars aren't page defined, then define them
	if (typeof(window.ads) == 'undefined')
		window.ads = true;

	if (typeof(window.fullEpisode) == 'undefined')
		window.fullEpisode = false;

	if (typeof(window.dartKeyValues) == 'undefined')
		window.dartKeyValues = "";
		
	if (typeof(window.css) == 'undefined') 
		window.css = "";
		
	if (typeof(window.relatedPath) == 'undefined')
		window.relatedPath = null;
		
	if (typeof(window.resize) == 'undefined')
		window.resize = "false";
		
	if (typeof(window.screenMode) == 'undefined')
		window.screenMode = "wide";
		
	if (typeof(window.defaultSize) == 'undefined')
		window.defaultSize = "";
		
	if (typeof(window.sizeOverride) == 'undefined')
		window.sizeOverride = false;
		
	if (typeof(window.autoPlay) == 'undefined')
		window.autoPlay = "";
		
	if (typeof(window.continuousPlay) == 'undefined')
		window.continuousPlay = "";
		
	if (typeof(window.vidContainer) == 'undefined')
		window.vidContainer = "MTVN_PL-video-player";
		
	if (typeof(window.mrssUrl) == 'undefined')
		window.mrssUrl = null;
		
	if (typeof(window.getUrl) == 'undefined')
		window.getUrl = false;
		
	if (typeof(window.dnao) == 'undefined')
		window.dnao = "";
		
	if (typeof(window.pnao) == 'undefined')
		window.pnao = "";
		
	if (typeof(window.defaultLang) == 'undefined')
		window.defaultLang = "en_UK";
		
	if (typeof(window.jsMode) == 'undefined')
		window.jsMode = false;
	
	if (typeof(window.embed) == 'undefined')
		window.embed = false;
		
	if (typeof(window.isLive) == 'undefined')
		window.isLive = false;
		
	if (typeof(window.moreVideos) == 'undefined')
		window.moreVideos = false;
		
	if (typeof(window.endSlate) == 'undefined')
		window.endSlate = false;
		
	if (typeof(window.franchise) == 'undefined')
		window.franchise = "";
		
	if (typeof(window.version) == 'undefined')
		window.version = "";
		
	if (typeof(window.subtitles) == 'undefined')
		window.subtitles = false;
		
	if (typeof(window.subDefaultLang) == 'undefined')
		window.subDefaultLang = "";
		
	if (typeof(window.subAuto) == 'undefined')
		window.subAuto = "";
		
	if (typeof(window.closecaption) == 'undefined')
		window.closecaption = false;

    
	var vidDiv = document.getElementById(window.vidContainer);
	var playerPath = window.location.pathname;
	var playerQuery = window.location.search;
	var sitePath = window.location.protocol + "//" + window.location.hostname;
	
	var configUrlQuery = getQueryValue('configUrl');
	if (configUrlQuery != "") {
		configUrl = configUrlQuery;
	}
	

	var mrssUrlQuery = getQueryValue('mrssUrl');
	if (mrssUrlQuery != "") {
		window.mrssUrl = mrssUrlQuery;
	}
	
	var devHost = "http://intl.esperanto.mtvi.com";
	if (sitePath.indexOf("-d.mtvi.com") != -1) {
		devHost = "http://intl.esperanto-d.mtvi.com";
	} else if (sitePath.indexOf("-q.mtvi.com") != -1) {
		//devHost = "http://intl.esperanto-q.mtvi.com";
		devHost = "http://intl.esperanto.mtvi.com";
	}
	
	if (configUrl == "") {
		configUrl = devHost + '/player/configuration.jhtml';
	} else {
		configUrl = devHost + configUrl;
	}
	
	// override embedded uri if passed via query
	var queryUri = getQueryValue('uri');
	if (queryUri) {
		uri = queryUri;
	}
	
	window.ads = (!window.ads) ? 'false' : 'true';
	window.fullEpisode = (window.fullEpisode) ? 'true' : 'false';
	window.keyValuePair = (window.dartKeyValues) ? '&keyValues=' + window.dartKeyValues : '';
	window.subtitles = (window.subtitles) ? 'true' : 'false';
		
	
	//for italy dual sponsorship
	if(window.mtvmItSponsor!=null && window.mtvmItSponsor!="" ){
	
		if(window.keyValuePair !=null && window.keyValuePair !="")
		{
			window.keyValuePair = window.keyValuePair+"adv_sp="+window.mtvmItSponsor+";";
		}
	}
	else
	{
		if(window.keyValuePair !=null && window.keyValuePair !="")
		{
			window.keyValuePair = window.keyValuePair+"adv_sp=none;";
		}
			
	}

	
	configUrl += "?ads=" + window.ads;
	configUrl += "&uri=" + uri;
	configUrl += "&css=" + window.css;
	configUrl += "&full=" + window.fullEpisode;
	configUrl += "&autoPlay=" + window.autoPlay;
	configUrl += "&continuousPlay=" + window.continuousPlay;
	configUrl += "&sitePath=" + sitePath;
	//moved so it's after configUrl has its :s taken out
	//configUrl += "&playerPath=" + playerPath;
	configUrl += "&resize=" + window.resize;
	configUrl += "&screenMode=" + window.screenMode;
	configUrl += "&getUrl=" + window.getUrl;
	configUrl += "&defaultLang=" + window.defaultLang;
	configUrl += "&jsMode=" + window.jsMode;
	configUrl += "&embed=" + window.embed;
	configUrl += "&isLive=" + window.isLive;
	configUrl += "&moreVideos=" + window.moreVideos;
	configUrl += "&endSlate=" + window.endSlate;
	configUrl += "&version=" + window.version;
	configUrl += window.keyValuePair;
	
	if (window.subtitles) {
		configUrl += "&subtitles=" + window.subtitles;
	}
	
	if (window.subDefaultLang != "") {
		configUrl += "&subDefaultLang=" + window.subDefaultLang;
	}
	
	if (window.subAuto != "") {
		configUrl += "&subAuto=" + window.subAuto;
	}
	
	if (window.closecaption) {
		configUrl += "&closecaption=" + window.closecaption;
	}
	
	if (playerQuery != null) {
		playerQuery = playerQuery.replace(/\&/g, "||");
		configUrl += "&playerQuery=" + playerQuery;
	}
	
	if (window.relatedPath != null) {
		window.relatedPath = window.relatedPath.replace(/\&/g, "||");
		configUrl += "&relatedPath=" + window.relatedPath;
	}
	
	if (mrssUrl != null) {
		configUrl += "&mrssUrl=" + mrssUrl;
	}
	
	if (window.dnao != "") {
		configUrl += "&dnao=" + window.dnao;
	}
	
	if (window.pnao != "") {
		configUrl += "&pnao=" + window.pnao;
	}
	
	if (window.franchise != "") {
		configUrl += "&franchise=" + window.franchise;
	}
	
	configUrl = configUrl.replace(/\:/g, "%7C");
	
	configUrl += "&playerPath=" + playerPath;
	
	configUrl = configUrl.replace(/\?/g, "%3F");
	configUrl = configUrl.replace(/\=/g, "%3D");
	configUrl = configUrl.replace(/\&/g, "%26");
	configUrl = configUrl.replace(/\http%7C/g, "http:");
	
	//*********** END GMP BLOCK ************//
	
	
	var playlistTitle = MTVN_PL.VideoHelper.flattenUGCTitle(MTVM.Playlist.getPlaylistName());
	
   
    
    var so = new SWFObject("http://intl.esperanto.mtvi.com/global/apps/player/flex/Loader.swf","embeddedPlayer",  660, MTVM.config.swfPlayer.height, "9.0.115.0", "#cccccc");
    so.addVariable("CONFIG_URL",configUrl);
    so.addVariable("playlistTitle",playlistTitle);
    so.addParam("allowFullScreen",true);
    so.addParam("enableJavascript",true);
    so.addParam("allowScriptAccess","always");
    so.addParam("swliveconnect",true);
    so.addParam("menu", false);
    so.addParam("bgcolor", "#000000");
    so.addParam("wmode", "transparent");
    so.write(window.vidContainer);
   

	/*console.log(flashVars);
	
	el.innerHTML =''+
		'<object height="'+MTVM.config.swfPlayer.height+'" width="660" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="player1">'+
		'<param value="always" name="allowScriptAccess"/>'+
		'<param value="true" name="allowFullScreen"/>'+
		'<param value="transparent" name="wmode"/>'+
		'<param value="http://intl.esperanto.mtvi.com/global/apps/player/flex/Loader.swf" name="movie"/>'+		
		'<param value="' + flashVars + '" name="flashvars" />'+		
		'<embed id="embeddedPlayer" height="'+MTVM.config.swfPlayer.height+'" width="660"'+
		'flashvars="' + flashVars + '"'+
		'menu="false" '+
		'swliveconnect="true" '+
		'allowscriptaccess="always" enablejavascript="true"'+ 
		'allowfullscreen="true" quality="high"'+ 
		'bgcolor="#000000" '+
		'name="embeddedPlayer"'+ 
		'style="" '+
		'src="http://intl.esperanto.mtvi.com/global/apps/player/flex/Loader.swf"'+ 
		'type="application/x-shockwave-flash"/>';
	*/    
    MTVN_PL.VideoHelper.controller = new MTVNPlayerController('embeddedPlayer','MTVN_PL.VideoHelper.onPlayerLoaded');

}


MTVN_PL.VideoHelper.onStateChange = function (state) {

	if (state == 'stopped' && this.isAd == false) {
		MTVN_PL.PlaylistManager.playNext();
	} else if (state == 'playing') {
		this.isAd = this.player.getMetadata().isAd;
	}else if(state =='stopped' && this.player.getMetadata().isAd == true)
	{
		MTVN_PL.PlaylistManager.playNext();
	}

}

MTVN_PL.VideoHelper.flattenUGCTitle = function ( playlistTitle ) {
	var re = /[^0-9A-Za-z\s]/g;
	var flattenedTitle = playlistTitle.replace(re, "");
	var re2 = /\s+/g;
	flattenedTitle = flattenedTitle.replace(re2, "_");
	flattenedTitle = MTVM.util.truncateString(flattenedTitle, 10);
	return flattenedTitle;
}


/********************************************************/
/********************* QUICKLIST PLAYBACK ***************/
/********************************************************/

// MK: Obsolete. See actions section
/*
MTVN_PL.PlaybackQuicklist.prototype.editAction = function (listID) {
	document.location = "/playlists/quicklist/modify/";
}*/

MTVN_PL.PlaybackQuicklist.prototype.genMessageSlate = function () 
{	
	var mesgSlate = new MTVM.Playlist.MessageSlate("quicklist");
	
	/*
	str ='';
	str +='<div class="MTVN_PL_messageSlate-container">';
	
	str +='<div class="MTVN_PL-messageSlate-header">';
	str +='<div class="MTVN_PL-messageSlate-header-text left">Quicklist Tip:</div>';
	str +='<div class="MTVN_PL-messageSlate-header-button right"><img src="/sitewide/img/buttons/redX.gif" height="9" width="9" border="0"/></div>';
	str +='<div class="clear"></div>';
	str +='</div>';
	
	str +='<div class="MTVN_PL-messageSlate-message">Save your quicklist as a Playlist to share it with friends, keep it longer than 24 hours or watch it on a different computer.</div>';	
	str +='</div>';*/

	return mesgSlate.getSlate();

}

MTVN_PL.PlaybackQuicklist.prototype.genFooterContents = function (playlist) {	
	str ='';
	str += '<div class="MTVN_PL-button-group">';
	
	if(playlist.contentList.length>0){

		str += str = this.genListEditButton ({ buttonTxt : MTVM.Playlist.Buttons.getEditButton({state:'default', style:'dark'})});
		str += str = this.genListSaveButton ({ buttonTxt : MTVM.Playlist.Buttons.getSaveAsAPlaylistButton({style:'dark'})});
	}
	str +="</div>";
	return str;
}

//*** Generates HTML for the list header
MTVN_PL.PlaybackQuicklist.prototype.genHeaderContents = function (playlist)
{
	var ad = MTVM.Playlist.getSponsorLogo('playback');


	if(typeof ad !="undefined" && ad != null && ad !=""  && ad !="null")
	{
		ad = ad;
	}
	else
	{
		ad ="";
	}
		
	var str = "<div class=\"MTVN_PL-titleWrapper\"><div class=\"MTVN_PL-title left\">"+ MTVN_PL.dictionary.getPhrase("MyQuicklist") +" </div>";
	str += " <div class=\"MTVN_PL-totalItems left\">(" + playlist.contentList.length + ")</div>";
	str += " <div class=\"right MTVN_PL-sponsorLogo\">"+ad+"</div>";
	str += " <div class=\"clear\"></div></div>";
	
	return str;
}



MTVN_PL.PlaybackQuicklist.prototype.genItemContents = function (item, position) {
		
	str = '';
	str += this.genItemNum(item, position);	
	str += MTVN_PL.PlaybackPlaylist.superproto.genItemContents.call(this, item, position);
	str += '<div class="MTVN_PL-play-text" id="play_'+MTVN_PL.util.sanitize(this.widgetID)+'"><div style="width:100px;"><img src="/sitewide/img/playlist/arrowGreen.gif" height="8" width="8" border="0"/> ' +
	unescape(MTVN_PL.dictionary.phrases.NowPlaying) + '</div></div>';
	return str;	
}


/********************************************************/
/********************* QUICKLIST EDIT *******************/
/********************************************************/


MTVN_PL.EditQuicklist.prototype.genFooterContents = function (playlist) 
{
	str = "";
	btnState = (playlist.contentList.length<1?"disabled":"");

	// MK: new code
	if(playlist.contentList.length>0){
		str += this.genListPlayButton ({ buttonTxt : MTVM.Playlist.Buttons.getPlayAllButton(btnState)});
		str += this.genListSaveButton({ buttonTxt : MTVM.Playlist.Buttons.getSaveAsAPlaylistButton({style:"white"}) });
	}
	
	
	// MK: old code
	//str += MTVN_PL.EditQuicklist.prototype.genPlayAllButton.call(this, 'quicklist');
	//str += ' <a href="javascript://" class="MTVN_PL-button MTVN_PL-button-save" onclick="MTVN_PL.EditQuicklist.prototype.onSave(\''+this.listID+'\'); return false">'+MTVM.Playlist.Buttons.getSaveAsAPlaylistButton()+'</a>';

	return str;
}




MTVN_PL.EditQuicklist.prototype.playAction = function (listID, widgetID)
{
	MTVM.services.Reporting.sendPlaylistPlayEvent();
	document.location = "/playlists/"+MTVM.Playlist.config.userUcid+"/"+listID;
}

MTVN_PL.EditQuicklist.prototype.genThumbnail = function (item, imgUrl) 
{
	return '<div class="MTVN_PL-thumbnail"><img src="' + imgUrl + '" /></div>';
}

MTVN_PL.EditQuicklist.prototype.genTitle = function (item, title) {
	// MK: new onclick code
	return '<span class="MTVN_PL-itemTitle">'+title+'</span><br />';
}


/********************************************************/
/****************** Last Added Playlist *****************/
/********************************************************/


MTVN_PL.LastAddedPlaylist.prototype.genHeaderContents = function (playlist) {
	var ad = MTVM.Playlist.getSponsorLogo();	
	var cssClass = MTVM.config.languageCode + "-" +MTVM.config.countryCode;
	if(typeof ad !="undefined" && ad != null && ad !=""  && ad !="null")
	{
		ad = ad;
	}
	else
	{
		ad ="";
	}
	
	var str = "<div class=\"MTVN_PL-titleWrapper\"><div class=\"MTVN_PL-title left\">"+MTVN_PL.dictionary.getPhrase("MyQuicklist")+" </div>";
	str += " <div class=\"MTVN_PL-totalItems left\">(" + playlist.contentList.length + ")</div>";
	str += " <div class=\"right MTVN_PL-sponsorLogo\">"+ad+"</div>";
	str += " <div class=\"clear\"></div></div>";
	
	return str;
}



MTVN_PL.LastAddedPlaylist.prototype.genItemContents = function (item, position) {
	
	var imgUrl = "";
	
	if(item!=null && item.data != null && item.data.thumbnail != null && item.data.thumbnail['url']!=null)
	{
		imgUrl = MTVN_PL.util.getValue(item.data.thumbnail['url'], MTVN_PL.Controller._configuration.defaultThumbnail);
	}
	
	
	var title = MTVN_PL.util.getValue(item.data.title, 'NO TITLE');
	var artist = MTVN_PL.util.getValue(item.data.artist, '');
		
	var str = '';
	str += '<div class="justAdded" style="float:left;">'+MTVM.lang.playlist.justAdded+'</div>'
	str += '<div class="MTVN_PL-itemDetail">';
	str += this.genTitle(item, title);
	str += '<span class="MTVN_PL-itemArtist">'+artist+'</span>';
	str += '</div>';
	str += '<div style="position: absolute; right: 4px; top: 8px;">';
	str += this.genListPlayButton({ buttonTxt : MTVM.Playlist.Buttons.getPlayAllButton() });
	str += '</div>';
	return str;
}


// *** Generates the html within the footer
MTVN_PL.LastAddedPlaylist.prototype.genFooterContents = function (playlist) {
	
	str = '';
	
	if(playlist.contentList.length>0){
		str += str = this.genListEditButton ({ buttonTxt : MTVM.Playlist.Buttons.getEditButton({style:"white"})});
		str += str = this.genListSaveButton ({ buttonTxt : MTVM.Playlist.Buttons.getSaveAsAPlaylistButton({style:"white"})});
	}
	return str;
}


// MK: Obsolete
/*
// *** When play all is clicked
MTVN_PL.LastAddedPlaylist.prototype.onPlayAll = function (listID)
{
	MTVM.services.Reporting.sendPlaylistPlayEvent();
	document.location = "/playlists/quicklist";
}*/




/********************************************************/
/**** Visitor LIST SET ********/
/********************************************************/
MTVN_PL.VisitorListSet = function(listSetParams, containerID, widgetID, listSetTitle) {
	MTVN_PL.VisitorListSet.superclass.apply(this, arguments);
}

MTVN_PL.extend(MTVN_PL.VisitorListSet, MTVN_PL.BaseListSet);

MTVN_PL.VisitorListSet.prototype.genHeaderContents = function (listSet) {

	var setTitle = ""
	if(listSet.length>0){
		setTitle = "Playlists "+MTVM.lang.playlist.by+" "+listSet[0].user.displayName;
	}
	else
	{
	
		setTitle = "MTVMusic Playlists";
	}
	
	str = '<div class="MTVN_PL-listset-modeswitch">';
	/*
	str += '<a href="javascript://" onclick="MTVN_PL.BaseListSet.prototype.setListMode(\''+this.widgetID+'\', \'thumbnail\'); return false" class="MTVN_PL-listset-thumbmode-link">Thumbnails</a>&nbsp;|&nbsp;';
	str += '<a href="javascript://" onclick="MTVN_PL.BaseListSet.prototype.setListMode(\''+this.widgetID+'\', \'list\'); return false" class="MTVN_PL-listset-listmode-link">List</a>';
	*/
	str += '</div>';
	str += '<div class="MTVN_PL-listset-title">' + setTitle + '</div>';
	str += '<div style="clear: both"></div>';
	return str;
}








/********************************************************/
/**** COLLECTION LIST SET aka MINILIST of LISTS *********/
/********************************************************/


MTVN_PL.CollectionListSet = function(listSetParams, containerID, widgetID, listSetTitle) {
	MTVN_PL.CollectionListSet.superclass.apply(this, arguments);
}

MTVN_PL.extend(MTVN_PL.CollectionListSet, MTVN_PL.BaseListSet);

MTVN_PL.CollectionListSet.prototype.truncateLength = 21;

// MK: Obsolete
/*
MTVN_PL.CollectionListSet.prototype.editAction = function (listID, widgetID) {
	document.location = "/playlists/"+MTVM.flux.getUserUcid()+"/"+listID+"/modify/";
}*/


MTVN_PL.CollectionListSet.prototype.cssClass = 'MTVN_PL-listset-edit MTVN_PL-listset-mode-thumbnail MTVN_PL-listset-collection';

MTVN_PL.CollectionListSet.prototype.genListContents = function (playlist) {	
	var str ='';
	var titleClassName ="";
	
	str = '<div class="MTVN_PL-listset-thumb">';
	str += this.genListThumbnailContents(playlist);
	str += '</div>';
	

	if(MTVM.Playlist.config.playlistMgid == playlist.contentURI){
		titleClassName = 'MTVN_PL-listset-details MTVN_PL-listset-details-highlighted';
	}
	else
	{		
		titleClassName = 'MTVN_PL-listset-details';
	}
	
	
	str += '<div class="'+titleClassName+'">';
	str += this.genListDetails(playlist);
	str += '</div>';

	return str;
}


MTVN_PL.CollectionListSet.prototype.genHeaderContents = function (listSet) {
	str = '<div class="MTVN_PL-listset-modeswitch">';
	str += '</div>';
	str += '<div class="MTVN_PL-listset-title">' + this.listSetTitle + '</div>';
	str += '<div style="clear: both"></div>';
	return str;
}
MTVN_PL.CollectionListSet.prototype.genFooterContents = function (listSet) {
	if(MTVM.flux.isUserLoggedInFlux())
	{
		str = '<div class="right MTVN_PL-listset-footer">'+this.genListCreateButton({buttonTxt : MTVM.Playlist.Buttons.getNewPlaylistButton()})+'</div><div class="clear"></div>';
	}
	else
	{
		str = '<div class="MTVN_PL-listset-footer"></div>';
	}
	return str;

}



MTVN_PL.CollectionListSet.prototype.genListThumbnailContents = function (playlist) {
	// MK: Obsolete
	//var editOnClick = 'MTVN_PL.BaseListSet.prototype.editAction(\''+playlist.contentURI+'\', \''+this.widgetID+'\');';	
	str = '';
	return str;
}

MTVN_PL.CollectionListSet.prototype.genListDetails = function (playlist) {
	// MK: Obsolete
	//var editOnClick = 'MTVN_PL.CollectionListSet.prototype.editAction(\''+playlist.contentURI+'\', \''+this.widgetID+'\');';	
	var titleClassName = '';
	var str = '';
	

	titleClassName = 'MTVN_PL-listset-listTitle';	
	
	str += '<div class="'+titleClassName+'">';
	
	str += '<div class="left"><a title="'+MTVM.util.escapeQuotes(playlist.name)+'"href="javascript://" '+this.genListEditOnClick({ listID : playlist.contentURI })+'>' + MTVM.util.truncateString(playlist.name, this.truncateLength)+ '</a></div>';	
	str += '<div class="right MTVN_PL-listset-totalItems" style="text-align:right;"> ('+playlist.itemCount+') </div><div class="clear"></div></div>';
	return str;
}



/********************************************************/
/********************* CONTROLLER ***********************/
/********************************************************/

MTVN_PL.Controller.loginAction = function()
{	
	parent.document.location = MTVM.config.fluxCommunityUrl+'/SignUp.aspx?returnPath='+encodeURIComponent(parent.document.location.href)+'&communityUcid='+MTVM.flux.getCommunityUcid();
}

MTVN_PL.Controller.joinAction = function () {
	document.location = MTVM.config.fluxCommunityUrl+'/JoinInterim.aspx?returnPath='+encodeURIComponent(parent.location.href)+'&communityUcid='+MTVM.flux.getCommunityUcid();
}


/********************************************************/
/********************* ACTION OVERLOADS *****************/
/********************************************************/
MTVN_PL.BasePlaylist.prototype.listPlayAction = function () {
	MTVM.services.Reporting.sendPlaylistPlayEvent();
	document.location = "/playlists/"+MTVM.Playlist.config.userUcid+"/"+this.listID;
}
MTVN_PL.BaseListSet.prototype.listEditAction = function (evtObj) {
	document.location = "/playlists/"+MTVM.Playlist.config.userUcid+"/"+evtObj.listID+"/modify/";
}

MTVN_PL.BaseListSet.prototype.listPlayAction = function (evtObj) {
	MTVM.services.Reporting.sendPlaylistPlayEvent();
	document.location = "/playlists/"+MTVM.Playlist.config.userUcid+"/"+evtObj.listID;
}

MTVN_PL.PlaybackPlaylist.prototype.listEditAction = function () {
	document.location = "/playlists/"+MTVM.Playlist.config.userUcid+"/"+MTVM.Playlist.config.playlistMgid+"/modify/";
}


MTVN_PL.EditQuicklist.prototype.listPlayAction = function () {
	MTVM.services.Reporting.sendQuicklistPlayEvent();
	document.location = "/playlists/quicklist/";
}
MTVN_PL.EditQuicklist.prototype.listConvertedAction = function (playlist) {
		//location = './playlist_edit.php?mgid='+playlist.contentURI;
		document.location = "/playlists/quicklist/modify/";
}



MTVN_PL.PlaybackQuicklist.prototype.listPlayAction = function () {
	MTVM.services.Reporting.sendQuicklistPlayEvent();
	document.location = "/playlists/quicklist/";
}

MTVN_PL.PlaybackQuicklist.prototype.listEditAction = function () {
	document.location = "/playlists/quicklist/modify/";
}


MTVN_PL.CollectionListSet.prototype.listEditAction = function (evtObj) {	
	document.location = "/playlists/"+MTVM.flux.getUserUcid()+"/"+evtObj.listID+"/modify/";
}



MTVN_PL.PlaybackQuicklist.prototype.listConvertedAction = function (playlist){
		//document.location = './playlist_playback.php?mgid='+playlist.contentURI;
		document.location = "/playlists/"+MTVM.flux.getUserUcid()+"/"+playlist.contentURI;
}


/********************************************************/
/********** BUTTON GENERATOR OVERLOADS ******************/
/********************************************************/

MTVN_PL.BaseWidget.prototype.genListShareButton = function (buttonProps) {
	
	var shareUrl 			= "http://"+document.location.hostname+"/playlists/"+MTVM.Playlist.config.userUcid+"/"+buttonProps.playlist.contentURI;	
	var shareOnMouseOut		= "addthis_close()";
	var playlistName 		= buttonProps.playlist.name;
	var shareOnClick		= "return addthis_open(this, \'\', \'"+shareUrl+"\', unescape(\'MTVMusic.com Playlist - "+escape(playlistName)+"\'))";
	
	var evtObj = {};
	var customAttributes = [
		{ attrName : 'onclick', attrValue : shareOnClick },
		{ attrName : 'onmouseout', attrValue : shareOnMouseOut }
		];
	return MTVN_PL.ButtonManager.genButton(buttonProps.buttonTxt, 'MTVN_PL-button-share', this.listShareAction, evtObj, this, true, customAttributes);
}


/********************************************************/
/********** BASE LIST OVERLOADS ******************/
/********************************************************/

MTVN_PL.BaseListSet.prototype.genHeaderContents = function (listSet) {
	str = '<div class="MTVN_PL-listset-modeswitch">';
	/*
	str += '<a href="javascript://" onclick="MTVN_PL.BaseListSet.prototype.setListMode(\''+this.widgetID+'\', \'thumbnail\'); return false" class="MTVN_PL-listset-thumbmode-link">Thumbnails</a>&nbsp;|&nbsp;';
	str += '<a href="javascript://" onclick="MTVN_PL.BaseListSet.prototype.setListMode(\''+this.widgetID+'\', \'list\'); return false" class="MTVN_PL-listset-listmode-link">List</a>';
	*/
	str += '</div>';
	str += '<div class="MTVN_PL-listset-title">' + this.listSetTitle + '</div>';
	str += '<div style="clear: both"></div>';
	return str;
}

/****************************************************/
/******************** Shows the playlist menu *******/
/****************************************************/
//ONLY OVERLOADED Z-INDEX CONFIG
//*** Shows the playlist menu
MTVN_PL.AddButtonManager.writeAddMenu = function (buttonID, contentURI) {
	if (this._addMenu != null) {
		this._addMenu.destroy();
		this._addMenu = null;
	}
	
	// The menu contents
	var aItems = [
		{
			text : MTVN_PL.dictionary.getPhrase('AddVideoTo'),
			id: "quicklistImg"
		},
		
	    {
	        text: MTVN_PL.dictionary.getPhrase('MyQuicklist'),
	        id: "quicklistMenuItem",
	        onclick : {
	        	fn : MTVN_PL.AddButtonManager.onMenuItemClick,
	        	obj : { listID : 'quicklist' }
	        }
	    }
	];
	
	// My playlist submenu
	var plMenuItem = {
        text: MTVN_PL.dictionary.getPhrase('MyPlaylists'),
        submenu: {
            id: "my_playlists", 
            itemdata: []
        } 
    }
	
	// Write login link if user is not logged in
	if (!MTVN_PL.Controller._configuration.userLoggedIn) {
		var clickObj = { fn : MTVN_PL.Controller.loginAction, obj : {} };
		plMenuItem.submenu.itemdata.push({ text : MTVN_PL.dictionary.getPhrase('Join') + ' | ' + MTVN_PL.dictionary.getPhrase('SignIn') + '...', onclick : clickObj });
	
	// Otherwise add the user's playlists
	} else {
		// Check to see if membership is required and the user is a member
		if (MTVN_PL.Controller._getConfigParam('requireMembership') == true && 
			MTVN_PL.Controller._getConfigParam('isCommunityMember') == false) {
			var clickObj = { fn : MTVN_PL.Controller.joinAction, obj : {} };
			plMenuItem.submenu.itemdata.push({ text : MTVN_PL.dictionary.getPhrase('JoinCommunity') + '...', onclick : clickObj });
		} else {
			// Add the 'create playlist' item
			var evtObj = { }
			var clickObj = { fn : MTVN_PL.AddButtonManager.onCreatePlaylistClick, obj : evtObj };
			plMenuItem.submenu.itemdata.push({ id : 'MTVN_PL-menu-new-playlist', text : MTVN_PL.dictionary.getPhrase('NewPlaylist') + '...', onclick : clickObj });
			
			// Add the user playlists into the menu structure
			for (var i = 0; i < this._userPlaylists.length; i++) {
				var evtObj = { listID : this._userPlaylists[i].contentURI };
				var clickObj = { fn : MTVN_PL.AddButtonManager.onMenuItemClick, obj : evtObj };
				plMenuItem.submenu.itemdata.push({ text : MTVN_PL.util.trunc(20, this._userPlaylists[i].name), onclick : clickObj });
			}
		}
	}
	
	aItems.push(plMenuItem);
	
	
	var config = { 
		position : 'dynamic', 
		//context : [ 'MTVN_PL-addButton-link-'+MTVN_PL.util.sanitize(buttonID), "tl", "tr" ], 
		shadow: true,
		iframe: false,
		//constraintoviewport: false,
		scrollincrement: 5,
		maxheight: 350,
		zIndex:6 //only thing changed by Brett
	};
	var oMenu = new YAHOO.widget.Menu('MTVN_PL-add-menu', config);
	oMenu.subscribe("render", function () {this.cfg.setProperty("maxheight", 350)});
	oMenu.addItems(aItems);
	oMenu.render('menuHolder');
	this._addMenu = oMenu;
}




