/****************** SELECT LANGUAGE **********************/
if(MTVM.config.playlistAppVersion != "1.0.2"){
	MTVN_PL.dictionary.phrases = MTVM.lang.playlist.translations.us;
}

/********************************************************/
/********************* 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 ********************/
/********************************************************/

//*** Adds an item to the list (removing scrollTop)
MTVN_PL.BasePlaylist.prototype._addItem = function (item) {
	MTVN_PL.debug('Adding item id: ' + item.unique_id + ' to list: ' + this.listID, 'BasePlaylist._addItem');
	
	var divs = this.getListContainer().getElementsByTagName('DIV');
	var itemSetContainer = this.getItemSetContainer();
	var items = [];
	
	for (var i=0; i < divs.length; i++) {
		
		// Pull all items into an array
		if (divs[i].id.match(/^MTVN_PL_.+_item_/)) {
			items.push(divs[i]);
		}
	}
	
	// Build new item
	itemSetContainer.innerHTML += this._genItemContainer (item, items.length);
	
	// Scroll to the bottom
//	itemSetContainer.scrollTop = itemSetContainer.scrollHeight * 2;
	
	// Update the header
	this.getHeaderContainer().innerHTML = this.genHeaderContents(MTVN_PL.PlaylistManager._allPlaylistsByURI[this.listID]);
	
	// Update the emptySlate
	this._setListEmptyState(this.playlist);
	
	// set the busy state
	this._setBusyState(false);
}

//Sets an item's play state (removing scrollTop)
MTVN_PL.BasePlaylist.prototype.playItem = function (itemID, contentURI) {
	var divs = this.getListContainer().getElementsByTagName('DIV');
	var itemContainer;
	for (var i=0; i < divs.length; i++) {
		if (divs[i].id.indexOf('MTVN_PL_' + MTVN_PL.util.sanitize(itemID)+'_item') == 0) {
			divs[i].className += ' MTVN_PL-playing';
			
			// scroll this item to the top of the list
		//	this.getItemSetContainer().scrollTop = divs[i].offsetTop;
		}
	}
	var itemIdx = MTVN_PL.PlaylistManager._getItemIndex(this.listID, itemID)+1;
	var itemsPerPage = 3;
	//for the HD content the player is wider and we display 4 items
	if (MTVM.Playlist.config.userUcid=="B74ED50101D54EB7000101D54EB7"){
	//	itemsPerPage = 4;
	}
	var page = Math.ceil(itemIdx / itemsPerPage);
	$J('.infiniteCarousel').trigger('goto', [page]);
	
	//passing the pagination data in order to use it later in "playlistTotal" DIV
	MTVN_PL.BasePlaylist.prototype.setCurrItem (itemIdx, itemsPerPage, page);
	
//	console.log("=========================================");
//	console.log("itemIdx: " + itemIdx);
//	console.log("page: " + page);
//	console.log("=========================================");
}

MTVN_PL.BasePlaylist.prototype.setCurrItem = function (itemIdx, itemsPerPage, page) {
	var currentPlaylist = MTVM.Playlist.getCurrentPlaylist(); 
	var totalItems = currentPlaylist.contentList.length;
	var minItemsOnPage = page * itemsPerPage - itemsPerPage + 1;
	var maxItemsOnPage = page * itemsPerPage;
	var pageVal = "(" + minItemsOnPage + "-" + maxItemsOnPage + " of " + totalItems + ")";
	if (totalItems < maxItemsOnPage){
		pageVal = "(" + minItemsOnPage +" - " + totalItems + " of " + totalItems + ")";
	}
	if (totalItems < maxItemsOnPage && itemIdx == totalItems){
		pageVal = "(" + itemIdx + " of " + totalItems + ")";
	}
	$J("#playlistTotal").html(pageVal);
}

/******* ADDING EXTRA BUTTON SEPERATOR INTO MTVN_PL OBJ*******/
MTVN_PL.BasePlaylist.prototype.buttonSeparator = '<span class="MTVN_PL-buttonSeparator">|</span>';

/*** Loading wording ***/
MTVN_PL.BasePlaylist.prototype.genLoadingContents = function () {
	var str = "";
	return str;
}

/*** Title of the widget ***/
MTVN_PL.BasePlaylist.prototype.truncateLength = 32;
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;
}


/*** single Item ***/
MTVN_PL.BasePlaylist.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);
		imgUrl = imgUrl.replace(/(width)=[0-9]*/i,"width=90");
		imgUrl = imgUrl.replace(/(height)=[0-9]*/i,"height=67");
	}
	
	var title = MTVN_PL.util.getValue(item.data.title, MTVN_PL.dictionary.getPhrase('NoTitle'));
	var artist = MTVN_PL.util.getValue(item.data.artist, '');
		
	var str = '';
	str += this.genThumbnail(item, imgUrl);
	str += '<div class="MTVN_PL-itemDetail">';
	str += this.genTitle(item, title);
	str += '<span class="MTVN_PL-itemArtist">'+artist+'</span>';
	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="/random">'+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.indexOf("null</a>")<0 && ad.indexOf("817-grey.gif")<0)
	{
		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;
}


MTVN_PL.BasePlaylist.prototype.genThumbnail = function (item, imgUrl) {
	var playOnClick = 'MTVN_PL.BasePlaylist.prototype.playAction(\''+item.mgid+'\', \''+this.listID+'\', \''+this.widgetID+'\', \''+ item.unique_id + '\'); MTVN_PL.VideoHelper.vidToBePlayed = \''+item.mgid+'\'; ';
	
	return '<div class="MTVN_PL-thumbnail"><a href="javascript://" onclick="'+playOnClick+'; return false;"><img src="' + imgUrl + '" /></a></div>';
}



// *** 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';
	var buttonStyle = "dark2";
	
	if (playlist.user.isCurrentUser) {
		str += '<span class="MTVN_PL-button-container">'+this.genListEditButton({ buttonTxt : MTVM.Playlist.Buttons.getEditButton({state:state, style:buttonStyle})})+'</span>';
		str += this.buttonSeparator;
	}
	str += '<span class="MTVN_PL-button-container">'+this.genListShareButton({ buttonTxt : MTVM.Playlist.Buttons.getShareButton({state:state, style:buttonStyle}), playlist : playlist })+'</span>';
	str += '</div>';
	

	
	return str;
}

/***************    Reset Items container height for sponsor logo ********************/
MTVN_PL.BasePlaylist.prototype.resetItemStyle = function()
{
		//while generating footer, set the height for .MTVN_PL-items
	if(typeof MTVM.Playlist.headerSponsor != "undefined" || MTVM.Playlist.headerSponsor !="none"){
			$J('div#playlist div.MTVN_PL-footer').ready(function(){
				$J('div#playlist div.MTVN_PL-header').css('display', 'none');
				$J('div#playlist div.MTVN_PL-items').css('height', '330px');
			});
	}
}


/********************************************************/
/********************* PLAYBACK PLAYLIST ****************/
/********************************************************/


//*** Generates the div container for the set of items
MTVN_PL.PlaybackPlaylist.prototype._genItemSet = function (playlist) {
	var str = '';
	str += '<div class="playlistContainer infiniteCarousel">';
	str += '<div class="MTVN_PL-items wrapper" id="'+this.itemSetContainerID+'" onscroll="MTVN_PL.PlaylistManager.onListScroll();">';
	str += '<ul>';
	str += this._genEmptySlate(playlist);
	for (var i = 0; i < playlist.contentList.length; i++) {
		// skip if an item times out
		if (playlist.contentList[i].data == '__TIMEOUT__') continue;
		str += '<li>';
		str += this._genItemContainer(playlist.contentList[i], i);
		str += '</li>';
	}
	str += '</ul>';
	str += '</div>';
	str += '</div>';
	return str;
}

MTVN_PL.PlaybackPlaylist.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);
		imgUrl = imgUrl.replace(/(width)=[0-9]*/i,"width=90");
		imgUrl = imgUrl.replace(/(height)=[0-9]*/i,"height=67");
	}
	
	var title = MTVN_PL.util.getValue(item.data.title, MTVN_PL.dictionary.getPhrase('NoTitle'));
	var truncatedTitle	= MTVM.util.truncateString(title, this.truncateLength);
	var artist = MTVN_PL.util.getValue(item.data.artist, '');
	artist = MTVM.util.truncateString(artist, 22);
		
	var playOnClick = 'MTVN_PL.BasePlaylist.prototype.playAction(\''+item.mgid+'\', \''+this.listID+'\', \''+this.widgetID+'\', \''+ item.unique_id + '\'); MTVN_PL.VideoHelper.vidToBePlayed = \''+item.mgid+'\'; ';
	str = '';
	str += this.genThumbnail(item, imgUrl);
	str += this.genItemNum(item, position) + '<br />';	
	str += '<div class="MTVN_PL-itemDetail">';
	str += this.genTitle(item, truncatedTitle);
	str += '<span class="by">'+MTVM.lang.playlist.by+'&nbsp;</span><span class="MTVN_PL-itemArtist">'+artist+'</span>';
	str += '</div>';
	str += '<div class="clear"></div>';
	str += '<div class="MTVN_PL-play-text" id="play_'+MTVN_PL.util.sanitize(this.widgetID)+'"><div class="entry-overlay left"></div></a></div>';
	return str;	
}


//*** Generates attributes for the item overlay div 
MTVN_PL.PlaybackPlaylist.prototype.genItemOverlayAttributes = function (item, position) {
	return 'onclick="MTVN_PL.BasePlaylist.prototype.playAction(\''+item.mgid+'\', \''+this.listID+'\', \''+this.widgetID+'\', \''+ item.unique_id + '\'); MTVN_PL.VideoHelper.vidToBePlayed = \''+item.mgid+'\'; ' +
		'MTVN_PL.util.stopPropagation(\'event\');"';
}


/*** Generates HTML for the list footer*/
MTVN_PL.PlaybackPlaylist.prototype.genFooterContents = function (playlist) {
	var state = playlist.itemCount > 0 ? '' : 'disabled';
	var buttonStyle = "dark2";
	
	str = '';	
	
	/* DEPRECATED OLD FOOTER ITEMS
	str += '<div class="MTVN_PL-button-group">';
	
	str += '<span class="MTVN_PL-button-container"><span id="buyButtonWrapper" class="right MTVM-playlist-button-dark2-buttonText"></span></span>';
	//str += this.buttonSeparator;
	str += '<span class="MTVN_PL-buttonSeparator" id="buyButtonSeparator">|</span>';
	
	str += '<span class="MTVN_PL-button-container"><span id="playlistAdd" class="right MTVM-playlist-button-dark2-buttonText"></span></span>';
	
	str += this.buttonSeparator;
	str += '<span class="MTVN_PL-button-container">'+this.genListShareButton({ buttonTxt : MTVM.Playlist.Buttons.getShareButton({state:state, style:buttonStyle}), playlist : playlist })+'</span>';
	
	if (playlist.user.isCurrentUser) {
		str += this.buttonSeparator;
		str += '<span class="MTVN_PL-button-container">'+this.genListEditButton({ buttonTxt : MTVM.Playlist.Buttons.getEditButton({state:state, style:buttonStyle})})+'</span>';
	}


	str += '<span id="playlistTotal" class="left MTVM-playlist-button-dark2-buttonText">';
	str += '</span>';
	
	str += '</div>';
	*/
	
	$J("#interactAddAsPlaylistSep").css('display', 'none');
	$J("#interactAddAsPlaylist").css('display', 'none');
	$J("#interactEditPlaylistSep").css('display', 'none');
	$J("#interactEditPlaylist").css('display', 'none');
	
	if (playlist.user.isCurrentUser) {
		$J("#interactEditPlaylistSep").css('display', 'block');
		$J("#interactEditPlaylist").css('display', 'block');
		var listEditButton = this.genListEditButton({ buttonTxt : MTVM.Playlist.Buttons.getEditButton({state:state, style:buttonStyle})});
		$J("#interactEditPlaylist").html(listEditButton);
	}
	
	this.resetItemStyle();
	
	/*### START GENERATE LINKS TO THE SIDE COLUMN ###*/
	str = '';
	
	return str;
}

MTVN_PL.PlaybackPlaylist.prototype.resetItemStyle = function()
{
		//while generating footer, set the height for .MTVN_PL-items
	if(typeof MTVM.Playlist.headerSponsor != "undefined" || MTVM.Playlist.headerSponsor !="none"){
			$J('div#playlist div.MTVN_PL-footer').ready(function(){
				$J('div#playlist div.MTVN_PL-header').css('display', 'none');
				$J('div#playlist div.MTVN_PL-items').css('height', '80px');
			});
	}
}

/********************************************************/
/********************* 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;
	
	// Video Startup Reporting
	MTVN_PL.VideoHelper.player.addEventListener('STATE_CHANGE','MTVNTimerStateCheck');

	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('PLAYHEAD_UPDATE', "MTVN_PL.VideoHelper.onPlayHeadUpdate");
	MTVN_PL.VideoHelper.player.addEventListener('NO_AD','MTVM.player.onNoAd');
}


MTVN_PL.VideoHelper.onPlay = function (eventObj, requestArgs) 
{	

	var el = document.getElementById('MTVN_PL-video-player');
	MTVN_PL.VideoHelper.domesticPlayer(eventObj, requestArgs, el);
	
}

MTVN_PL.VideoHelper.domesticPlayer = function(eventObj, requestArgs, el)
{
	var userPlaylistId	= MTVM.contextValues.user_playlist_id ? MTVM.contextValues.user_playlist_id.substring(MTVM.contextValues.user_playlist_id.lastIndexOf(":")+1) : "";
	var userId			= "";
	if(typeof typeof MTVM.Playlist.getCurrentPlaylist() == "object" && typeof MTVM.Playlist.getCurrentPlaylist().user =="object")
	{
		if(MTVM.Playlist.getCurrentPlaylist().user!=null){	
			userId = MTVM.Playlist.getCurrentPlaylist().user.externUserID;
		}
	}	
	
	if(MTVN_PL.VideoHelper.controller == null)
	{ 			
		var playerHeight = MTVM.config.swfPlayer.heightPrime;	
		var playerWidth = MTVM.config.swfPlayer.widthPrime;	
		
		/*
		if (MTVM.Playlist.config.userUcid=="B74ED50101D54EB7000101D54EB7"){
			playerHeight = MTVM.config.swfPlayer.hdHeightPrime;
			playerWidth = MTVM.config.swfPlayer.hdWidthPrime;
			$J(document).ready(function() {
				$J("#player-playlist-container .infiniteCarousel .wrapper").css("width","688px");
			});
		}
		*/

		el.innerHTML = 
			'<object height="'+playerHeight+'" width="'+playerWidth+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="player">'+
			'<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;NID=82125&amp;sid=MTVHive_Playlist&amp;franchise_name='+franchise_name+'&amp;playlist_name='+playlist_name+'" name="flashvars" />'+
			'<embed height="'+playerHeight+'" width="'+playerWidth+'" allowscriptaccess="always" allowfullscreen="true" '+
			' wmode="transparent" '+
			'flashvars="autoPlay=true&amp;NID=82125&amp;sid=MTVHive_Playlist&amp;franchise_name='+franchise_name+'&amp;playlist_name='+playlist_name+'"'+
			' type="application/x-shockwave-flash" name="player" id="player" src="'+MTVM.config.mtvnservicesURL+'/'+eventObj.contentURI+'"/>'+
			'</object>';
		
		MTVN_PL.VideoHelper.controller = new MTVNPlayerController('player','MTVN_PL.VideoHelper.onPlayerLoaded');
		
		// Load the carousel below the Player
		$J('.infiniteCarousel').infiniteCarousel();
		
	}else{
		//console.log(MTVN_PL.VideoHelper.controller.player) 
		//if (MTVN_PL.VideoHelper.controller.player.getMetadata().isAd){

		//} else {
			if(MTVN_PL.VideoHelper.vidToBePlayed != null && MTVN_PL.VideoHelper.vidToBePlayed != "")
			{	
				MTVN_PL.VideoHelper.controller.player.pause();
				MTVN_PL.VideoHelper.controller.player.playUri(MTVN_PL.VideoHelper.vidToBePlayed);
			}
			else				
			{
				MTVN_PL.VideoHelper.controller.player.pause();
				MTVN_PL.VideoHelper.controller.player.playUri(eventObj.contentURI);
			}
		//}
	}
}

//for choicestream	
MTVN_PL.VideoHelper.onPlayHeadUpdate =function()
{
	if(MTVN_PL.VideoHelper.controller.player.getPlayheadTime()>20)		
	{		
		if(MTVN_PL.VideoHelper.controller.player.getMetadata().isAd == false)
		{
			MTVM.services.Reporting.ChoiceStream.sendEvent(MTVN_PL.VideoHelper.player.getMetadata().guid.match(/[0-9].*/), "purchase");
		}
	}
}
MTVN_PL.VideoHelper.onStateChange = function (state) {

		if(state == "stopped"){		
			MTVM.services.Reporting.ChoiceStream.reset();
		}
		if(state == "playing" && this.player.getMetadata().isAd == false){		
			MTVM.services.Reporting.ChoiceStream.sendEvent(MTVM.contextValues.vid, "view");
		}
		
		if (state == 'stopped' && this.beforeVidIsAd == false)
		{	
			
			if(MTVN_PL.VideoHelper.vidToBePlayed == null || MTVN_PL.VideoHelper.vidToBePlayed=="")
			{
				MTVN_PL.PlaylistManager.playNext();
				MTVM.services.Reporting.ChoiceStream.reset();
				}
			else
			{	
				MTVN_PL.VideoHelper.vidToBePlayed = "";	
			}
		} else if (state == 'playing'){

			
			this.beforeVidIsAd = this.player.getMetadata().isAd;
			
			if(this.player.getMetadata().isAd == false)
			{
				MTVN_PL.VideoHelper.vidToBePlayed = "";
			}
			
		}else if(state =='stopped' && this.player.getMetadata().isAd == true){
			MTVM.services.Reporting.ChoiceStream.reset();
			
			if(MTVN_PL.VideoHelper.vidToBePlayed == null || MTVN_PL.VideoHelper.vidToBePlayed=="")
			{				
				MTVN_PL.PlaylistManager.playNext();
			}
			else
			{				
				MTVN_PL.VideoHelper.vidToBePlayed = "";	
			}
		}
}

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;
}




//*** Generates HTML for the list header
MTVN_PL.PlaybackPlaylist.prototype.genHeaderContents = function (playlist)
{
	var ad = MTVM.Playlist.getSponsorLogo('playback');
	var sponsoredBy = "";
	if(typeof ad !="undefined" && ad != null && ad !=""  && ad !="null" && ad.indexOf("null</a>")<0 && ad.indexOf("817-grey.gif")<0)
	{
		ad = ad;
		MTVM.Playlist.headerSponsor = ad;
	}
	else
	{
		ad ="";
		MTVM.Playlist.headerSponsor = "none";
	}

	var str = "";
	
	
	
	if(ad==""){
		str = "<div class=\"MTVN_PL-titleWrapper\" style=\"display:none;\">";
	}else{
		str = "<div class=\"MTVN_PL-titleWrapper\">";
	}
			
	str += " <div class=\"right MTVN_PL-sponsorLogo\">"+ad+"</div>";
	str += " <div class=\"clear\"></div></div>";
		
	
	return str;
}


/********************************************************/
/********************* QUICKLIST PLAYBACK ***************/
/********************************************************/

MTVN_PL.PlaybackQuicklist.prototype.genMessageSlate = function () 
{	
	var mesgSlate = new MTVM.Playlist.MessageSlate("quicklist");


	return mesgSlate.getSlate();

}

MTVN_PL.PlaybackQuicklist.prototype.genFooterContents = function (playlist) {	
	str = '';	
	
	/* DEPRECATED 
	str += '<span class="MTVN_PL-button-container"><span id="buyButtonWrapper" class="right MTVM-playlist-button-dark2-buttonText"></span></span>';
	//str += this.buttonSeparator;
	str += '<span class="MTVN_PL-buttonSeparator" id="buyButtonSeparator">|</span>';
	str += '<span class="MTVN_PL-button-container"><span id="playlistAdd" class="right"></span></span>';
	
	str += '<div class="MTVN_PL-button-group">';
	var buttonStyle = "dark2";
	
	if(playlist.contentList.length>0){
		str += this.buttonSeparator;
		str += '<span class="MTVN_PL-button-container">'+this.genListSaveButton ({ buttonTxt : MTVM.Playlist.Buttons.getSaveAsAPlaylistButton({style:buttonStyle})})+'</span>';
		str += this.buttonSeparator;
		str += '<span class="MTVN_PL-button-container">'+this.genListEditButton ({ buttonTxt : MTVM.Playlist.Buttons.getEditButton({state:'default', style:buttonStyle})})+'</span>';

			
		str += '<span id="playlistTotal" class="left MTVM-playlist-button-dark2-buttonText">';
		str += '(' + (MTVN_PL.PlaylistManager._getItemIndex(this.listID, playlist.contentList[0].unique_id)+1) + ' of ' + playlist.contentList.length + ')';
		str += '</span>';
	}

	str +="</div>";
	*/
	
	var buttonStyle = "dark2";
	
	$J("#interactAddAsPlaylistSep").css('display', 'none');
	$J("#interactAddAsPlaylist").css('clear', 'left');
	
	var listSaveButton = this.genListSaveButton ({ buttonTxt : MTVM.Playlist.Buttons.getSaveAsAPlaylistButton({style:buttonStyle})});
	var listEditButton = this.genListEditButton ({ buttonTxt : MTVM.Playlist.Buttons.getEditButton({state:'default', style:buttonStyle})});
	
	$J("#interactAddAsPlaylist").html(listSaveButton);
	$J("#interactEditPlaylist").html(listEditButton);
	
	
	this.resetItemStyle();
	
	str = '';
	
	return str;
}

//*** Generates HTML for the list header
MTVN_PL.PlaybackQuicklist.prototype.genHeaderContents = function (playlist)
{
	var ad = MTVM.Playlist.getSponsorLogo('playback');
	var sponsoredBy = "";
	if(typeof ad !="undefined" && ad != null && ad !=""  && ad !="null" && ad.indexOf("null</a>")<0 && ad.indexOf("817-grey.gif")<0)
	{
		ad = ad;
		MTVM.Playlist.headerSponsor = ad;
	}
	else
	{
		ad ="";
		MTVM.Playlist.headerSponsor = "none";
	}
	
	var str = "";
	
	
	if(ad==""){
		str = "<div class=\"MTVN_PL-titleWrapper\" style=\"display:none;\">";
	}else{
		str = "<div class=\"MTVN_PL-titleWrapper\">";
	}
			
	str += " <div class=\"right MTVN_PL-sponsorLogo\">"+ad+"</div>";
	str += " <div class=\"clear\"></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"}) });
	}
	
	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.indexOf("null</a>")<0 && ad.indexOf("817-grey.gif")<0)
	{
		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;
}



/********************************************************/
/**** 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 += '</div>';
	str += '<div class="ribPageHeadingDiv left">';
	str += '<h1 class="ribPageHeading"><div class="txt">' + setTitle + '</div></h1>';
	str += '<div class="ribbon-triangle"><img src="/sitewide/img/misc/title_corner.gif" title="" alt="" /></div>';
	str += '<div class="clear"></div>';
	str += '</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="ribPageHeadingDiv left">';
	str += '<h1 class="ribPageHeading"><div class="txt">' + this.listSetTitle + '</div></h1>';
	str += '<div class="ribbon-triangle"><img src="/sitewide/img/misc/title_corner.gif" title="" alt="" /></div>';
	str += '<div class="clear"></div>';
	str += '</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;
}


/********************************************************/
/********************* 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 shareUrl 			= document.location;
	var shareOnMouseOut		= "addthis_close()";
	var playlistName 		= buttonProps.playlist.name;
	var shareOnClick		= "return addthis_open(this, \'\', \'"+shareUrl+"\', unescape(\'MTVHive.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 += '</div>';
	str += '<div class="ribPageHeadingDiv left">';
	str += '<h1 class="ribPageHeading"><div class="txt">' + this.listSetTitle + '</div></h1>';
	str += '<div class="ribbon-triangle"><img src="/sitewide/img/misc/title_corner.gif" title="" alt="" /></div>';
	str += '<div class="clear"></div>';
	str += '</div>';
	return str;
}

/***********************************************************/
/************* AUTHENTICATION WIDGET FLUX 3.0 **************/
/***********************************************************/

// Flux Overlay Authentication - SignIn / SignUp / Interim Forms
var authenticationWidgetFlux3 = {
	createSignInWidget: function() {
		Flux.createWidget('Authentication', { fluxHosted: true },
			function(authenticationWidget) {
				authenticationWidget.showSignInForm();
			}
		);
	},
	createSignUpWidget: function() {
		Flux.createWidget('Authentication', { fluxHosted: true },
			function(authenticationWidget) {
				authenticationWidget.showSignUpForm();
			}
		);
	},
	createInterimWidget: function() {
		Flux.createWidget('Authentication', { fluxHosted: true },
			function(authenticationWidget) {
				authenticationWidget.showInterimForm();
			}
		);
	}
}

/*
// Forcing Reload - Required to redraw playlist menu after Flux Overlay Authentication
function onSignOut() {
	window.location.reload();
}
function onSignIn(context) {
	window.location.reload();
}
Flux.loadContext(function(context) {
	if (context.user) {
		context.onSignOut = onSignOut;
	} else {
		context.onSignIn = onSignIn;
	}
});
*/

/***********************************************************/
/*********** END AUTHENTICATION WIDGET FLUX 3.0 ************/
/***********************************************************/

/****************************************************/
/******************** 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 (MTVM.flux.isUserLoggedInFlux4() == false) {
		var clickObj = { fn : authenticationWidgetFlux3.createSignInWidget, 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 && 
				window.Widgets4Context.user.communityMember == false) {
			var clickObj = { fn : authenticationWidgetFlux3.createInterimWidget, 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;
}


MTVN_PL.VideoHelper.placeVideo = function(divId) //with divId, will insert a new node after it 
{
	var currNode = null;
	var newNode = null;
	if(divId==null || divId=="")
	{
		document.write('<div id="MTVN_PL-video-player"></div>');	
	}
	else
	{
		currNode = document.getElementById(divId);
		newNode = document.createElement('div');
		newNode.setAttribute('id', "MTVN_PL-video-player");
		//currNode.parentNode.insertBefore(newNode, currNode.nextSibling);
		currNode.appendChild(newNode);
	}
}

//Places a playlist container into a page
MTVN_PL.PlaylistManager.placeTransientList = function (transientParams, widgetClass, autoPlay, divId) {
	var parentNode = "";
	var playlistNode ="";
	var loadingNode ="";

	
	transientParams.contentURI = MTVN_PL.util.sanitize(transientParams.contentURI);
	var listID = transientParams.contentURI;
	
	var widgetID = MTVN_PL.Controller.newWidgetID();
	
	var autoPlay = autoPlay == true ? true : false;
	
	// ID for the widget container
	var containerID = MTVN_PL.util.sanitize(listID + '_list_' + widgetID);
	
	// make a new widget based on whatever class was passed in
	var widget = new widgetClass(listID, containerID, widgetID, autoPlay);
	
	if(divId==null || divId=="")
	{
		document.write('<div id="'+containerID+'" class="MTVN_PL MTVN_PL-list '+widget.cssClass+'">'+
				'<div class="MTVN_PL-loading">'+widget.genLoadingContents()+'</div></div>');
	}
	else
	{
		parentNode = document.getElementById(divId);
		
		playlistNode = document.createElement('div');
		playlistNode.setAttribute('id', containerID);
		playlistNode.setAttribute('class', "MTVN_PL MTVN_PL-list "+widget.cssClass);

		loadingNode = document.createElement('div');		
		loadingNode.setAttribute('class', "MTVN_PL-loading");
		loadingNode.innerHTML = widget.genLoadingContents();
		
		playlistNode.appendChild(loadingNode);
		
		parentNode.appendChild(playlistNode);

	}
		
	
	if (this._widgetRegistry[listID] == undefined)
		this._widgetRegistry[listID] = [];
	this._widgetRegistry[listID].push(widget);
	this._widgetLists[MTVN_PL.util.sanitize(widgetID)] = widget;
	
	if (this._allPlaylistsByURI[listID] == undefined && this._listsWaitingForResolve[listID] == undefined) {
		this._listsWaitingForResolve[listID] = true;
		
		// Fire off call to get data
		MTVN_PL.Controller.resolveTransientList(transientParams, widgetID);	
	}
}


//adding choice stream
//Event handler for after an item is added
MTVN_PL.AddButtonManager.onItemAdded = function (eventObj, listID) {	
	MTVM.services.Reporting.ChoiceStream.sendEvent(eventObj.mgid.match(/[0-9].*/), "cartItemAdd");
	MTVN_PL.AddButtonManager.setPostClickState('added');
}

