MTVM.Playlist.config = { //set in html_page.xsl; during page load
	playlistMgid:null,
	userUcid:null
}

MTVM.Playlist.config.controller = //configuration for MTVN_PL aka playlist api
{
	debug:				(function(){switch(MTVM.config.serverPlatform){
												case "l": return true; break;
												case "d":return true; break;
												case "q":return false; break;
												default:return false; break;
											}})(),
	version:			MTVM.config.playlistAppVersion,
												
	appID: 				MTVM.config.playlistAppId,	
	playlistHost:		MTVM.config.playlistServicesURL,
	tokenGenURL:		'http://'+MTVM.config.playlistServicesURL+'/token_gen/flux',	
	defaultThumbnail:	MTVM.config.serverHostName+'/sitewide/img/default/140-105.jpg',
	
	loginSystem:		'flux'
	
}

	

/***************************************************/
/******************** HELPER METHODS ***************/
/***************************************************/

MTVM.Playlist.loadScripts = function()
{
	//load playlist Scripts	
	document.write('<script language="javascript" type="text/javascript" src="http://'+MTVM.config.playlistServicesURL+'/client/'+MTVM.Playlist.config.controller.version+'/js/dependencies.js?lang='+MTVM.config.languageCode+'-'+MTVM.config.countryCode+'" id="MTVN_PL-dependencies"></script>');
	document.write('<script language="javascript" type="text/javascript" src="http://'+MTVM.config.playlistServicesURL+'/client/'+MTVM.Playlist.config.controller.version+'/js/core.js" id="MTVN_PL-core"></script>');

}


MTVM.Playlist.isOwner = function()
{
	if(MTVM.Playlist.config.userUcid == MTVM.flux.getUserUcid())
	{return true;}
	else
	{return false;}
}

MTVM.Playlist.getPlaylistType =  function()
{
	var playlistType = "";
	var widget		 = null;

	try{
		widget = MTVN_PL.PlaylistManager._widgetLists["_"+MTVN_PL.PlaylistManager._playingWidgetID];
		if(widget != null)
		{
			if(widget.listID=="quicklist")
			{
				playlistType= "quicklist";
			}
			else
			{
				playlistType = "savedPlaylist";
			}
		}
		
	}catch (e){console.log(e);}
	
	return playlistType;
}

		
MTVM.Playlist.getPlaylistName =  function()
{
	var widget = null;
	var playlistName	 = "";
	
	try{
		if(MTVN_PL.PlaylistManager._playingWidgetID != null) // get name of the playing widget
		{
			widget = MTVN_PL.PlaylistManager._widgetLists["_"+MTVN_PL.PlaylistManager._playingWidgetID];

			if(widget != null)
			{
				if(widget.listID=="quicklist")
				{
					playlistName = MTVM.lang.playlist.myQuicklist;	
				}
				else
				{
					playlistName = widget.playlist.name;
				}
			}
		}else
		{		
			//MTVN_PL.PlaylistManager.
			
		}		
	}catch (e){console.log(e);};
	
	return playlistName;
}

MTVM.Playlist.getCurrentPlaylist =  function()
{
	var widget		 = null;
	var playlist	= null;
	try{
		widget = MTVN_PL.PlaylistManager._widgetLists["_"+MTVN_PL.PlaylistManager._playingWidgetID];
		if(widget != null)
		{
			playlist = MTVN_PL.PlaylistManager._allPlaylistsByURI[widget.listID];
		}
		
	}catch (e){console.log(e);}
	
	return playlist;
}


MTVM.Playlist.getPlaylistDate = function(mgid)
{
	var playlist=""
	var date = null;

	if(mgid!="" && mgid !=null)
	{
		playlist = MTVN_PL.PlaylistManager._allPlaylistsByURI[mgid]
	}
	else
	{
		playlist = MTVM.Playlist.getCurrentPlaylist();
	}
	
	if(playlist!=null && playlist!="")
	{
		var myDate = new Date( playlist.createdate *1000);
		date = myDate.getFullYear()+"-"+myDate.getMonth()+"-"+myDate.getDate();
	}
	return date;
}

MTVM.Playlist.goToListSet = function(ucid)
{
	var address = "";
	if(ucid == null || ucid == "")
	{
		address = MTVM.config.serverHostName + "/playlists/"+MTVM.flux.getUserUcid()+"/";
	
	}
	else
	{
		address = MTVM.config.serverHostName + "/playlists/"+ucid+"/";
		
	}
	document.location = address;
}


MTVM.Playlist.goToQuicklist = function(ucid)
{	
	{
		document.location = MTVM.config.serverHostName +  "/playlists/quicklist";
	}
}


//deprecated
MTVM.Playlist.buildPlaylistTitle = function()
{
	var playlistName = (MTVM.Playlist.getPlaylistName()?MTVM.Playlist.getPlaylistName():MTVM.lang.playlist.myPlaylist);
	$J('#playlistTitle').innerHTML = MTVM.lang.playlist.edit+" "+playlistName;	
}

MTVM.Playlist.reloadIframe = function(obj)
{	
	
	var iframe = document.getElementById("widgetIframe");
	iframe.src = "http://"+ document.location.hostname + "/sitewide/dataservices/videoDetails/?mgid="+obj.contentURI+"&referrerPlaylistMgid="+MTVM.Playlist.config.playlistMgid+"&referrerUserUcid="+MTVM.Playlist.config.userUcid;		
}



MTVM.Playlist.setCollectionName = function()
{
	
	try{
		if(MTVN_PL.ListSetManager._widgetRegistry[0].listSet!= null)
		{							
			$J(".MTVN_PL-listset-title").html("Playlists "+MTVM.lang.playlist.by+" "+MTVN_PL.ListSetManager._widgetRegistry[0].listSet[0].user.displayName);
		}
		else
		{
			$J(".MTVN_PL-listset-title").html(MTVM.lang.playlist.memberPlaylists);
		}
	}catch(e){MTVM.log("MTVM.Playlist.setCollectionName"+e, 2)}
}


/*
 * Setting MTVM.ContextValues so that moreByArtist widget can pick up the artist alias and video id.
 * 
 */
MTVM.Playlist.setMTVMParams = function(type, value)
{
	switch(type)
	{
		case "artistAlias":
			MTVM.contextValues.artistAlias = value;
			break;
		
		/*
		case "artistName":
			MTVM.contextValues.fullArtistName = value;
			break;
		*/
		
		case "videoMgid":
			MTVM.contextValues.vid = value;
			break;
			
	}
	
}


MTVM.Playlist.swapItemClass = function(obj, state)
{
	var MOUSE_OVER_CLASS = "MTVN_PL-item-mouseOver";
	var tempClassName = "";

	switch(state)
	{
		case "out":
				tempClassName = obj.className;
				tempClassName = tempClassName.replace(MOUSE_OVER_CLASS, "");
				
				obj.className = tempClassName;							
			break;
		
		case "over":
				obj.className = obj.className+" "+MOUSE_OVER_CLASS;
			break;
	}
}



MTVM.Playlist.listenAndUpdateQuicklistCount = function(item) //required function see MTVM.Playlist.updateQuicklistCount's comments for explanation
{	
	MTVM.Playlist.updateQuicklistCount();
	MTVM.log("MTVM.playlist: listenAndUpdateQuicklistCount: ");
}

MTVM.Playlist.updateQuicklistTries = 0;

MTVM.Playlist.updateQuicklistCount = function(playlist)
{	
	MTVM.Playlist.updateQuicklistTries = MTVM.Playlist.updateQuicklistTries + 1;
	
	MTVM.log("MTVM.playlist: updateQuicklistCount: ");
	var contentLength = 0;
	var itemCount = 0;
	if(typeof MTVN_PL != "undefined" )
	{	
		itemCount = MTVM.Playlist.updateQuicklistCount.__getCount();				
		if(itemCount !="")
		{
			MTVM.Playlist.updateQuicklistCount.__addToDom(itemCount);
			MTVN_PL.Controller.addListener(MTVN_PL.Controller.ADD_ITEM, MTVM.Playlist.listenAndUpdateQuicklistCount, this); //rewiring to listenAndUpdateQuicklistCount because ADD_ITEM return track obj isntead of playlist
			MTVN_PL.Controller.addListener(MTVN_PL.Controller.DELETE_ITEM, MTVM.Playlist.listenAndUpdateQuicklistCount, this);							
		}
		else
		{
			if(MTVM.Playlist.updateQuicklistTries < 10)
			{
				setTimeout('MTVM.Playlist.updateQuicklistCount()', 1000);
			}	
			
			MTVN_PL.Controller.addListener(MTVN_PL.Controller.RESOLVE_LIST, MTVM.Playlist.listenAndUpdateQuicklistCount, this);			
		}
			
	}else
	{
		MTVM.log("MTVN_PL not exist");
	}
}

MTVM.Playlist.updateQuicklistCount.__getCount = function(playlist)
{
	MTVM.log("MTVM.playlist: updateQuicklistCount.__getCount: ");
	var contentLength = 0;
	if(typeof playlist != "undefined" && playlist!=null && playlist != "")
	{	
		contentLength = playlist.contentList.length;
	}
	else
	{	
		if(typeof MTVN_PL.PlaylistManager._allPlaylistsByURI["quicklist"] !="undefined" && MTVN_PL.PlaylistManager._allPlaylistsByURI["quicklist"].contentList.length)
		{	
			contentLength = MTVN_PL.PlaylistManager._allPlaylistsByURI["quicklist"].contentList.length;
		}else{			
			MTVN_PL.Controller.addListener(MTVN_PL.Controller.RESOLVE_LIST, MTVM.Playlist.listenAndUpdateQuicklistCount, this);	
		}
			
	}
	return contentLength;
}


MTVM.Playlist.updateQuicklistCount.__addToDom = function(contentLength)
{
	MTVM.log("MTVM.playlist: updateQuicklistCount.__addToDom: ");
	
	var myQuicklistString = MTVM.lang.playlist.myQuicklist;
	
	if(typeof $J('#playlistLinks-quicklist')[0] != "undefined" && $J('#playlistLinks-quicklist')[0] !="") // populate DOM with 
	{	
		$J('#playlistLinks-quicklist a').html(myQuicklistString + " ("+contentLength+")");
	}
	else if(typeof $J('#F_playlistLinks-quicklist')[0] != "undefined" && $J('#F_playlistLinks-quicklist')[0] != "") // populate DOM with 
	{	
		document.getElementById('F_playlistLinks-quicklist').innerHTML= '<a href="'+MTVM.config.serverHostName+'/playlists/quicklist/">'+myQuicklistString + ' ('+contentLength+')</a>';
	}

}





MTVM.Playlist.MetaTags = {}
MTVM.Playlist.MetaTags.get = function()
{
	
}

/***************************************************/
/******************** BUTTONS **********************/
/***************************************************/
MTVM.Playlist.Buttons = {
	newPlaylist:		"",
	rename: 			"",
	playPrevious:		"",
	playNext: 			"",
	playAll:			"",
	saveAsAPlaylist:	"",
	edit:				"",
	share:				""
}

MTVM.Playlist.Buttons.getNewPlaylistButton = function(state)
{	
	var button = new MTVM.services.ui.button.playlistWhite({buttonText:{content:MTVM.lang.playlist.newPlaylist}});
	/*switch(state)
	{
		default:
		button= '<img src="/sitewide/img/spacer.gif" class="btnNewPlaylist" alt="New Playlist"/>';
		break;
	}*/
	return button.BUTTON_HTML;
}

MTVM.Playlist.Buttons.getRenameButton = function(state)
{
	var button = new MTVM.services.ui.button.playlistWhite({buttonText:{content:MTVM.lang.playlist.rename}});
	/*switch(state)
	{
		default:
		button= '<img src="/sitewide/img/spacer.gif" class="btnRename" alt="Rename"/>';
		break;
	}*/
	return button.BUTTON_HTML;
}


MTVM.Playlist.Buttons.getPlayPreviousButton = function(state)
{
	var button = "";
	switch(state)
	{
		default:
		button= '<img src="/sitewide/img/spacer.gif" class="btnPlayPrevious" alt="'+MTVM.lang.playlist.playPrevious+'"/>';
		break;
	}
	return button;
}


MTVM.Playlist.Buttons.getPlayNextButton = function(state)
{
	var button = "";
	switch(state)
	{
		default:
		button= '<img src="/sitewide/img/spacer.gif" class="btnPlayNext" alt="'+MTVM.lang.playlist.playPrevious+'"/>';
		break;
	}
	return button;
}

MTVM.Playlist.Buttons.getPlayAllButton= function(state)
{
	var button = new MTVM.services.ui.button.playlistPink({buttonText:{content:MTVM.lang.playlist.playAll}});
	
	switch(state)
	{
		/*case "disabled":
		button= '<img src="/sitewide/img/spacer.gif" class="btnPlayAllDisabled" alt="Play All"/>';
		break;

		default:
		button= '<img src="/sitewide/img/spacer.gif" class="btnPlayAll" alt="Play All"/>';
		break;*/
	}
	return button.BUTTON_HTML;
}


MTVM.Playlist.Buttons.getSaveAsAPlaylistButton= function(props)
{
	var button = "";
	switch(props.style)
	{
		case "dark":
		button= new MTVM.services.ui.button.playlistDark({buttonText:{content:MTVM.lang.playlist.saveAsAPlaylist}})
		break;

		default:
		button= new MTVM.services.ui.button.playlistWhite({buttonText:{content:MTVM.lang.playlist.saveAsAPlaylist}})
		break;
	}
	return button.BUTTON_HTML;
	
	
}





MTVM.Playlist.Buttons.getEditButton = function(props)
{
	var button = "";
	switch(props.style)
	{
		case "dark":
			button = new MTVM.services.ui.button.playlistDark({buttonText:{content:MTVM.lang.playlist.edit}});
			break;
		default:			
			if(props.state == 'disabled'){
				button = new MTVM.services.ui.button.playlistWhite({buttonText:{content:MTVM.lang.playlist.edit, className:"MTVM-playlist-button-white-buttonText-disabled"}});
			}else{
				button = new MTVM.services.ui.button.playlistWhite({buttonText:{content:MTVM.lang.playlist.edit}});
			}
			break;
	}
	
	return button.BUTTON_HTML;
}

MTVM.Playlist.Buttons.getShareButton = function(props)
{
	var button = "";
	switch(props.style)
	{
		default:
			button = new MTVM.services.ui.button.playlistDark({buttonText:{content:MTVM.lang.playlist.shareThisPlaylist}});
			break;

		case "white":			
			button = new MTVM.services.ui.button.playlistWhite({buttonText:{content:MTVM.lang.playlist.shareThisPlaylist}});
			break;
	}
	
	return button.BUTTON_HTML;
}


MTVM.Playlist.Buttons.getShareButtonEvents = function(playlist)
{
	var shareUrl 			= "http://"+document.location.hostname+"/playlists/"+MTVM.Playlist.config.userUcid+"/"+playlist.contentURI;	
	var shareOnMouseOut		= "addthis_close()";
	var shareOnClick		= "return addthis_open(this, \'\', \'"+shareUrl+"\', \'MTVMusic.com Playlist - "+playlist.name+"\')";
	var shareString			= ' onclick="'+shareOnClick+'"  onmouseout="'+shareOnMouseOut+'" ';
	
	return shareString;
}





/***************************************************/
/************ MESSAGE/TIP SLATE IN PLAYLIST ********/
/***************************************************/
MTVM.Playlist.MessageSlate = function(messageType)
{
	this.MESSAGE_TYPE			= messageType;
	this.QUICKLIST_TIP_MESSAGE	= '<div class="MTVN_PL_messageSlate-container" id="MTVN_PL_messageSlate">'+	
										'<div class="MTVN_PL-messageSlate-header">'+
											'<div class="MTVN_PL-messageSlate-header-text left">'+MTVM.lang.playlist.quicklistTipTop+':</div>'+
											'<div class="MTVN_PL-messageSlate-header-button right" onclick="MTVM.Playlist.MessageSlate.prototype.onClickEvent(this, \'quicklist\');"><img src="/sitewide/img/buttons/redX.gif" height="9" width="9" border="0"/></div>'+
											'<div class="clear"></div>'+
										'</div>'+	
										'<div class="MTVN_PL-messageSlate-message">'+MTVM.lang.playlist.quicklistTipBot+'</div>'+
									'</div>';
}


MTVM.Playlist.MessageSlate.prototype = 
{
	getSlate:function()
	{
		//check cookie exists and not null
		if(this.__checkCookie())
		{
			return "";
		}
		else
		{
			//shorten playlist height TODO cannot be done till the box is drawn.. need to rethink			
			return this.__getMessage();
		}
	},
	
	__checkCookie:function()
	{
		var value = MTVM.util.getCookie(this.MESSAGE_TYPE);
		if(value!=null && value !="")
		{
			return true;
		}
		else
		{
			return false;
		}
	},
	
	__getMessage:function()
	{
		var mesg = "";
		switch(this.MESSAGE_TYPE)
		{
			case "quicklist":
				mesg = this.QUICKLIST_TIP_MESSAGE;
				break;
		}
		
		return mesg;
	},
	
	onClickEvent:function(obj, messageType)
	{
		if(messageType != null && messageType !="")
		{
		
		}else{
			messageType = this.MESSAGE_TYPE;
		}

		//make playlist restore to original size TODO
		$J("#MTVN_PL_quicklist_list_0_items").height( $J("#MTVN_PL_quicklist_list_0_items").height() - $J("#MTVN_PL_messageSlate").height());
		
		//hide slate
		obj.parentNode.parentNode.style.display = "none";
		
		
		//set cookie 
		MTVM.util.setCookie(messageType, "read")
		
	}
	
}

 


/***************************************************/
/***************** BREADCRUMB BUILDER **************/
/***************************************************/

MTVM.Playlist.VideoBreadcrumb = 
{
	videoObj:	null,
	
	get		: function(obj)
	{
		MTVM.Playlist.VideoBreadcrumb.videoObj = obj;
		MTVM.Playlist.VideoBreadcrumb.__loadData(obj.contentURI);
	},
	
	__loadData	: function(contentUri)
	{
		try{
			$J.ajax({			
				url: '/sitewide/dataservices/videoInfo/getVideoInfo/',
				type: 'GET',
				data: "mgid="+contentUri+"&showComments=false",
				dataType: 'json',
				timeout: 10000,

				error: function(){
					MTVM.log("MTVM.Playlist.VideoBreadcrumb: load JSON failed", 3);
				},

				success: function(json)
				{
					MTVM.Playlist.VideoBreadcrumb.__processJSON(json);
				}

			});
		}
		catch(e)
		{
			MTVM.log("MTVM playlist breadcrumb loadData failed "+e, 2);
		}
	},
	
	__processJSON:	function(json)
	{
		
		var jsonObj = eval(json);
		
		var artistAlias	= jsonObj.artistAlias;
		var artistName	= jsonObj.artistName;
		var contentUri	= jsonObj.videoMgid;		
		var videoTitle	= jsonObj.videoTitle;
		var artistUrl	= jsonObj.artistUrl;
		
		try{						

				
			MTVM.Playlist.setMTVMParams("artistAlias", 	artistAlias);
			MTVM.Playlist.setMTVMParams("artistName", 	artistName);
			MTVM.Playlist.setMTVMParams("videoMgid", 	contentUri);
						
			MTVM.EventsManager.broadcast("onPlaylistBreadcrumbReady");			
			this.__buildBreadcrumb(artistAlias, artistName, contentUri, videoTitle, artistUrl);
		}
		catch(e)
		{
		}
	},
		

	__buildBreadcrumb:	function(artistAlias, artistName, contentUri, videoTitle, artistUrl)
	{	
		var breadcrumb = "<h1 class=\"grey title\">"+ MTVM.Playlist.getPlaylistName()+" » <a class=\"blue title bold\" href=\""+artistUrl+"\">"+artistName+"</a> » "+videoTitle+" </h1>";		
		var e = document.getElementById("pageTitle");		
		e.innerHTML = breadcrumb;
		
		var addToPlayListButton = document.getElementById("playlistAddButtonDiv");
		if (addToPlayListButton!=null){
			$J(addToPlayListButton).next().remove();
			$J(addToPlayListButton).remove();
		}
		MTVM.Playlist.domRenderButtonWithText(contentUri);
		
	}
}


/***************************************************/
/**************** PLAYLIST DETAILS *****************/
/***************************************************/
MTVM.Playlist.Details ={}

MTVM.Playlist.Details.populate = function()
{
	MTVM.log("MTVM.playlist: Details.populate: ");
	var personalProfile = "";	
	
	if(typeof MTVN_PL != "undefined")
	{		
		if(MTVN_PL.PlaylistManager._widgetRegistry[MTVM.Playlist.config.playlistMgid] != null)	//playlist in dom, populate data
		{
			personalProfile = new MTVM.Playlist.Details.PersonalProfile(MTVM.Playlist.config.userUcid);
		}
		else //playlist not yet in dom, listen for it
		{			
			MTVN_PL.Controller.addListener (MTVN_PL.Controller.RESOLVE_LIST, MTVM.Playlist.Details.populate, this);
		}
	}
}


MTVM.Playlist.Details.Date = 
{
	__getDateFromParent: function()
	{
		MTVM.log("MTVM.playlist: Details.date.__getDateFromParent: ");
	
		//var urlParams = MTVM.util.parseUrlParamsToJSON();
		var playlist ="";
		var date ="";

		playlist = MTVN_PL.PlaylistManager._allPlaylistsByURI[MTVM.Playlist.config.playlistMgid];

		if(playlist!=null && playlist!="")
		{
			var myDate = new Date(playlist.createdate *1000);
			if(MTVM.config.countryCode == "us")
			{
				date = myDate.getMonth()+"/"+myDate.getDate()+"/"+myDate.getFullYear();
			}
			else
			{
				date = myDate.getDate()+"/"+myDate.getMonth()+"/"+myDate.getFullYear();
			}
		}
	
		return date;
	},
	
	populate: function()
	{
		MTVM.log("MTVM.playlist: Details.date.populate: ");
		
		var date = this.__getDateFromParent();		

		if(date!=null && date!="")//fill in date
		{
				document.getElementById("playlist-createdDate").innerHTML = "on " + date;
		}
	}

}


MTVM.Playlist.Details.PersonalProfile = function(userUcid)
{
	MTVM.log("MTVM.playlist: Details.PersonalProfile: ");
	
	this.userUcid = userUcid;
	this.userProfile = null;	
	this.__loadData();
}


MTVM.Playlist.Details.PersonalProfile.prototype =
{
	__loadData	: function()
	{
		var thisPtr = this;
		try{
			$J.ajax({
				url: '/sitewide/dataservices/daapiPeople/',
				type: 'GET',
				data: "showComments=off&userUcid="+thisPtr.userUcid,
				dataType: 'json',
				timeout: 20000,

				error: function(){
					MTVM.log('MTVM.Playlist.Details.PersonalProfile: Error loading AJAX document', 2);
				},
				
				success: function(json)
				{
					thisPtr.__processData(json);
				}
			});
		}
		catch(e)
		{
			MTVM.log("Playlist Details Personal Profile : loadData failed " + e, 2);
			this.userProfile = "";
		}
	},
	

	__processData:	function(json)
	{
		try{
			this.userProfile = json;
			this.__populateDom();
			
		}
		catch(e)
		{
			MTVM.log("Playlist Details Personal Profile:  processData failed " + e, 2);
			this.userProfile = "";
		}
	},
	
	__populateDom: function()
	{
		var userTitle = this.userProfile.title?this.userProfile.title:this.userProfile.firstName+this.userProfile.lastName;

		if(document.getElementById("playlist-details") == null || document.getElementById("playlist-details")=="")
		{
			$J("#pageTitle").after('<div id="playlist-details" style="display: block;"><span id="playlist-creator"></span><span id="playlist-createdDate"></span></div>');
		}
		
		if(this.userProfile != null &&  this.userProfile != "")
		{
			document.getElementById("playlist-details").style.display = "block";
			document.getElementById("playlist-creator").innerHTML = "Playlist "+MTVM.lang.playlist.createdBy+": <a class=\"blue\" href=\"/playlists/"+this.userUcid+"\">"+userTitle+"</a> ";
			MTVM.Playlist.Details.Date.populate();
		}
		else
		{
			document.getElementById("playlist-details").style.display = "none";
		}
	}
}






/***************************************************/
/***************************************************/
/***************** ADD BUTTON BUILDER **************/
/***************************************************/

MTVM.Playlist.domRenderButtonWithText = function(mgid){
	MTVM.log("MTVM.playlist: domRenderButtonWithText: ");
	
	if(typeof jQuery == 'function'){
		var addButtonDivId = "playlistAddButtonDiv";
		var addButtonDiv = $J("<div></div>").addClass("left d-inline");
			addButtonDiv.attr("id", addButtonDivId);
			addButtonDiv.css("padding","3px 0 0 15px");
			addButtonDiv.html(MTVN_PL.AddButtonManager.renderButton(mgid));
			
		var addButtonText = $J("<div></div>").addClass("left d-inline");
			addButtonText.css("padding","4px 0 0 3px");
			addButtonText.html('<span class="red txtReg">'+MTVM.lang.playlist.addToPlaylist+'</span>');
		
	
		$J('#playlistAdd').append(addButtonDiv);
		$J(addButtonDiv).after(addButtonText);
	}

	
	/*
	var buttonHTML = '<div class="left d-inline" style="padding: 3px 0 0 15px;">'
					+ MTVN_PL.AddButtonManager.renderButton(mgid) +
					'</div>
					<div class="left d-inline" style="padding: 9px 0 0 3px;">
						<span class="red txtSmall">Add to Playlist</span>
					</div>';
	*/
}



/*
*
* Ad Sponsor Logo Creator
* 
*/

MTVM.Playlist.getSponsorLogo =  function(module)
{
	var cssClass = MTVM.config.languageCode + "-" +MTVM.config.countryCode;
	var logo = "";
	
	switch(module)
	{
		case "playback":
			logo = '<a href="'+$J('#MTVM_PL_playbackSponsorLogo a')[0]+'" target="_blank" class="'+cssClass+'">'+ $J('#MTVM_PL_playbackSponsorLogo a').html() +'</a>';
			break;
		
		default:
			logo = '<a href="'+$J('#MTVM_PL_sponsorLogo a')[0]+'" target="_blank" class="'+cssClass+'">'+ $J('#MTVM_PL_sponsorLogo a').html() +'</a>';
	}

	return logo;
}

















/***************************************************************/
/***************** Playlist Video Details Reloader *************/
/***************************************************************/
MTVM.Playlist.reloadVideoDetails = function(param)
{	
	
	var reloader =null;	
	if(typeof param =="object")
	{
		MTVM.log("MTVM.Playlist.reloadVideoDetails activated: "+param.contentURI);
		reloader  = new MTVM.Playlist.VideoDetailsReloader(param.contentURI);
	}
	else
	{	
		MTVM.log("MTVM.Playlist.reloadVideoDetails activated: "+param);
		reloader = new MTVM.Playlist.VideoDetailsReloader(param);

	}
}

MTVM.Playlist.VideoDetailsReloader = function(playlistVidMgid)
{
	this.reset(); //reset first!
	
	
	this.playlistVidMgid = playlistVidMgid;
	
	
	MTVM.EventsManager.addListener("onFluxComments3Ready", 		MTVM.Playlist.VideoDetailsReloader.prototype.updateFluxWidgets, this);
	MTVM.EventsManager.addListener("onFluxContentAction2Ready", MTVM.Playlist.VideoDetailsReloader.prototype.updateFluxWidgets, this);
	MTVM.EventsManager.addListener("onFluxUsageReady", 			MTVM.Playlist.VideoDetailsReloader.prototype.updateFluxWidgets, this);		
	
	
	MTVM.EventsManager.addListener("onVideoDetailsReloaderDataSerivceReady", MTVM.Playlist.VideoDetailsReloader.prototype.showAllDetails, this);
	MTVM.EventsManager.addListener("onVideoDetailsReloaderDataSerivceReady", MTVM.Playlist.VideoDetailsReloader.prototype.updateMTVMParams, this);
	MTVM.EventsManager.addListener("onVideoDetailsReloaderDataSerivceReady", MTVM.Playlist.VideoDetailsReloader.prototype.updateBreadcrumb, this);		
	MTVM.EventsManager.addListener("onVideoDetailsReloaderDataSerivceReady", MTVM.Playlist.VideoDetailsReloader.prototype.updateVideoInfo, this);
	MTVM.EventsManager.addListener("onVideoDetailsReloaderDataSerivceReady", MTVM.Playlist.VideoDetailsReloader.prototype.updateShareEmbed, this);
	MTVM.EventsManager.addListener("onVideoDetailsReloaderDataSerivceReady", MTVM.Playlist.VideoDetailsReloader.prototype.showDivs, this);
	MTVM.EventsManager.addListener("onVideoDetailsReloaderDataSerivceReady", MTVM.Playlist.VideoDetailsReloader.prototype.updateMTVMWidgets, this);


	this.updateFluxWidgets();

	MTVM.log("MTVM.Playlist.VideoDetailsReloader activated"); //logging call needs to be placed after fluxevent listeners. possible racing condition. will need to optimize logging later.	
	
	MTVM.Playlist.VideoDetailsReloader.DataService.get(playlistVidMgid);
	
}



/*** RESET Reloader *****/
MTVM.Playlist.VideoDetailsReloader.prototype.reset = function()
{	
	MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.reset activated", 3);
	try{
		this.hideAllDetails();
		MTVM.EventsManager.removeAllListeners("onVideoDetailsReloaderDataSerivceReady");
		MTVM.EventsManager.removeAllListeners("onFluxComments3Ready");
		MTVM.EventsManager.removeAllListeners("onFluxContentAction2Ready");
		MTVM.EventsManager.removeAllListeners("onFluxUsageReady");
		
	}catch(e){
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.reset failed "+e , 2);
	}	

}


/*** Update MTVM show dives ***/
MTVM.Playlist.VideoDetailsReloader.prototype.showDivs = function()
{
	MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.showDivs activated", 3);
	try{
		if(document.getElementById('contentTopRow')!=null && document.getElementById('contentTopRow').style.display=="none")
		{
			document.getElementById('contentTopRow').style.display="block";
			document.getElementById('contentBottomRow').style.display="block";
		}
	}catch(e){
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.showDivs failed "+e , 2);
	}
}
	
/*** Update MTVM Widgets ***/
MTVM.Playlist.VideoDetailsReloader.prototype.updateMTVMWidgets = function()
{
	MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateMTVMWidgets activated", 3);
	
	var videoJSON = MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON
	var artistAlias =	"";
	var artistName =	"";
	var videoId =		videoJSON.id;
	var relatedVideos;
	var moreHDVideos;
	var playlistsContainerVideo;
	var moreVideosByArtist;
	artistName=videoJSON.artists[0].name;
	artistAlias = videoJSON.artists[0].alias;	

	if(videoJSON.largestRenditionWidth >= 12800)
	{
		moreHDVideos			 = new MTVM.widgets.moreHDVideos("moreHDVideos", {videoId:videoId});
	}
	
	
	moreVideosByArtist		 = new MTVM.widgets.moreVideosByArtist("moreByArtist", {videoId:videoId});
	relatedVideos			 = new MTVM.widgets.relatedVideosByArtist("relatedVideosByArtist", {videoId:videoId});	
	playlistsContainingVideo = new MTVM.widgets.playlistsContainingVideo("playlistsContainingVideo", {itemId:videoId});

}



/*** Update MTVM Params ***/
MTVM.Playlist.VideoDetailsReloader.prototype.updateMTVMParams = function()
{
	MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateMTVMParams activated", 3);

	var videoJSON = MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON
	
	var artistAlias =	"";
	var artistName =	"";
	var videoId =		videoJSON.id;
	var genreAlias  = videoJSON.primaryGenre.alias;
	//artist name/alias
	artistName=videoJSON.artists[0].name;
	artistAlias = videoJSON.artists[0].alias;		
	
	MTVM.contextValues.artistAlias = artistAlias;	
	MTVM.contextValues.genre	   = genreAlias; 
	MTVM.contextValues.vid		   = videoId;
	MTVM.contextValues.vid_type = "music_video";
	
	/*MTVM.Playlist.setMTVMParams("artistAlias", artistAlias);
	MTVM.Playlist.setMTVMParams("artistName", artistName);
	MTVM.Playlist.setMTVMParams("videoMgid", videoId);*/
}


/*** Update flux widgets: Comments, usage line, contentAction ***/
MTVM.Playlist.VideoDetailsReloader.prototype.updateFluxWidgets = function()
{	
	MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateFluxWidgets activated");

	try{		
		if(typeof Flux == "object" && typeof Flux.EventManager == "object")
		{
			//all widgets are present
			if(Flux.EventManager._widgets["Comments3"] && Flux.EventManager._widgets["Usage"] && Flux.EventManager._widgets["ContentAction2"])
			{
				Flux.EventManager.updateWidgetsWithNewContentId__(this.playlistVidMgid);
			}
		}
	}
	catch(e)
	{
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateFluxWidgets : failed :" + e, 2);		
	}
}
	
/*** Update Breadcrumbs ***/
MTVM.Playlist.VideoDetailsReloader.prototype.updateBreadcrumb = function()
{	
	MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateBreadcrumb activated");
	var videoJSON = MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON

	var artistAlias =	"";
	var artistName	=	"";
	var contentUri	=	videoJSON?videoJSON.contentUri:"";
	var videoId		=	videoJSON?videoJSON.id:"";
	var videoTitle	=	videoJSON?videoJSON.title:"";	
	var breadcrumb;	
	var e;

	
	try{		
	
		if(MTVM.Playlist.getPlaylistType() != "quicklist")
		{
			artistName=videoJSON.artists[0].name;
			artistAlias = videoJSON.artists[0].alias;		
					
		
			breadcrumb = "<h1 class=\"grey title\">"+ MTVM.Playlist.getPlaylistName()+" » <a class=\"blue title bold\" href=\"/"+MTVM.lang.urls.artist+"/"+artistAlias+"\">"+artistName+"</a> » "+videoTitle+" </h1>";		
			e = document.getElementById("pageTitle");		
			e.innerHTML = breadcrumb;

		}
	}
	catch(e)
	{
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateBreadcrumb  : failed :" + e, 2);		
	}
}

/*** Get Embed ***/
MTVM.Playlist.VideoDetailsReloader.prototype.getEmbed = function()
{	
	var videoJSON = MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON;

	//artist name/alias
	artistName=videoJSON.artists[0].name;
	artistAlias = videoJSON.artists[0].alias;
	var embed = '&lt;embed src="http://media.mtvnservices.com/mgid:uma:video:mtvmusic.com:'+videoJSON.id+'" width="512" height="319" type="application/x-shockwave-flash" flashVars="dist=http://www.mtvmusic.com" allowFullScreen="true" AllowScriptAccess="always"&gt;&lt;/embed&gt;&lt;div style="margin:0; text-align:center; width:512px;font-family:Arial,sans-serif;font-size:10px;"&gt;&lt;a style="color:#000000;" href="http://www.mtvmusic.com/'+artistAlias+'"&gt;'+MTVM.util.escapeQuotes(artistName)+'&lt;/a&gt; |&lt;a style="color:#000000;" href="http://www.mtvmusic.com/"&gt;MTV Music&lt;/a&gt;&lt;/div&gt;';
	
	return embed;
}


/*** Update Share Embed ***/
MTVM.Playlist.VideoDetailsReloader.prototype.updateShareEmbed = function()
{	
	MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateShareEmbed activated");
	var videoJSON = MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON;

	//artist name/alias
	artistName=videoJSON.artists[0].name;
	artistAlias = videoJSON.artists[0].alias;		
	
	var embedHtml = ''+
	'<div class="left" style="line-height:16px; padding-right:5px;">'+MTVM.lang.playlist.embed+'</div>'+
	'<div class="copyButtonWrapper left">'+
	'	<div class="left copyText">'+
	'		<input type="text" value=\'&lt;embed src="http://media.mtvnservices.com/'+MTVM.config.mgidPrefix+videoJSON.id+'" width="512" height="319" type="application/x-shockwave-flash" flashVars="dist=http://www.mtvmusic.com" allowFullScreen="true" AllowScriptAccess="always"&gt;&lt;/embed&gt;&lt;div style="margin:0; text-align:center; width:512px;font-family:Arial,sans-serif;font-size:10px;"&gt;&lt;a style="color:#000000;" href="'+MTVM.config.serverHostName+'/'+MTVM.lang.urls.artist+'/'+artistAlias+'"&gt;'+MTVM.util.escapeQuotes(artistName)+'&lt;/a&gt; | &lt;a style="color:#000000;" href="'+MTVM.config.serverHostName+'/"&gt;'+MTVM.lang.site.name+'&lt;/a&gt;&lt;/div&gt;\' onclick="this.select();" id="videoEmbedInput"/>'+
	'	</div>'+
	'	<div class="copyButton">'+
	'		<object height="17" width="50" id="embed2" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">'+
	'			<param name="allowScriptAccess" value="always"/>'+
	'			<param name="allowFullScreen" value="true"/>'+
	'			<param name="wmode" value="transparent"/>'+
	'			<param name="movie" value="/sitewide/flash/setClipboard.swf"/>'+
	'			<param name="flashvars" value="functionName=MTVM.util.Clipboard.copyEmbed"/>'+
	'			<embed height="17" width="50" type="application/x-shockwave-flash" src="/sitewide/flash/setClipboard.swf" style="" id="setClipboard2" name="setClipboard" bgcolor="#ffffff" quality="high" wmode="transparent" allowscriptaccess="always" flashvars="functionName=MTVM.util.Clipboard.copyEmbed"/>'+
	'		</object>'+
	'	</div>'+
	'	<div class="copyButtonGfx">';
	
	MTVM.services.ui.button.buttonList["copyButton1"] = new MTVM.services.ui.button.white19({buttonText:{content:MTVM.lang.video.copy}});
	embedHtml = embedHtml+MTVM.services.ui.button.buttonList["copyButton1"].BUTTON_HTML;	
	
	
	embedHtml= embedHtml+'</div><br style="clear: both;"/>'+
	'</div>';
	
	jQuery('#embedShare').html(embedHtml);
	
}


/*** Update Video Info ***/
MTVM.Playlist.VideoDetailsReloader.prototype.updateVideoInfo = function()
{	
	MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateVideoInfo activated");
	
	var videoJSON = MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON;
	var addToPlayListButton;
	var isHD = false;
	
	try{		
		if(videoJSON.largestRenditionWidth >= 12800)
		{
			isHD = true;
			MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice.get(videoJSON.seriesId);
		}
		//thumbnail		
		if(isHD)
		{
			jQuery("#videoDetails-thumbnail").html('<img src="/sitewide/img/logo/palladia.gif" class="videoThumb left"/>');
			//dvd link
			if(videoJSON.ecomURL!=null && videoJSON.ecomURL!="")
			{jQuery("#videoDetails-buyDvd").html('<a href="'+videoJSON.ecomURL+'" class="red">'+MTVM.lang.playlist.buyDvd+'</a>');}
			
		}
		else
		{	jQuery("#videoDetails-thumbnail").html("<img alt=\"\" src=\"http://mtvmusic.mtvnimages.com/uri/"+MTVM.config.mgidPrefix+videoJSON.id+"?width=140&height=105\" />");		
		}
		
		//artist name
		jQuery('#videoDetails-artistName .videoDetailsAttrName').html('<a href="/'+MTVM.lang.urls.artist+'/'+videoJSON.artists[0].alias+'" class="blue title bold">'+videoJSON.artists[0].name+'</a>');	
		
		//song title
		jQuery('#videoDetails-artistName .videoDetailsAttrVal').html('<span class="bold title">'+videoJSON.title+'</span>');
		
		//album
		if(videoJSON.albums.length >0)
		{
			jQuery('#videoDetails-album').css('display', 'block');
			if(videoJSON.albums.length && videoJSON.albums.length>1)
			{jQuery('#videoDetails-album .videoDetailsAttrVal').html(videoJSON.albums[0].title);}
			else
			{jQuery('#videoDetails-album .videoDetailsAttrVal').html(videoJSON.albums[0].title);}
		}		
		else{
			jQuery('#videoDetails-album').css('display', 'none');
		}
		
		//label
		if(videoJSON.label && videoJSON.label !=" "){
			jQuery('#videoDetails-label').css('display', 'block');
			//jQuery('#videoDetails-label .videoDetailsAttrVal').html('<a class="red" href="/search/?targetSearch=label&term='+escape(videoJSON.label)+'">'+videoJSON.label+'</a>');
			jQuery('#videoDetails-label .videoDetailsAttrVal').html(videoJSON.label);
		}else
		{
			jQuery('#videoDetails-label').css('display', 'none');
		}
		
		//director
		if(videoJSON.director){
			jQuery('#videoDetails-director').css('display', 'block');
			//jQuery('#videoDetails-director .videoDetailsAttrVal').html('<a class="red" href="/search/?targetSearch=director&term='+escape(videoJSON.director)+'">'+videoJSON.director+'</a>');
			jQuery('#videoDetails-director .videoDetailsAttrVal').html(videoJSON.director);
		}
		else{
			jQuery('#videoDetails-director').css('display', 'none');
		}
		
		//featuring
		if(videoJSON.artists && (videoJSON.artists.name == null || videoJSON.artists.name == "") && videoJSON.artists.length >1)
		{
			jQuery('#videoDetails-featuring').css('display', 'block');
			
			var featuredArtists ="";
			for(var i = 1; i<videoJSON.artists.length; i++)
			{				
				featuredArtists = featuredArtists + '<a href="/'+MTVM.lang.urls.artist+'/'+videoJSON.artists[i].alias+'" class="red">'+videoJSON.artists[i].name+'</a>';
				if(i<videoJSON.artists.length - 1)
				{featuredArtists = featuredArtists +", ";}
			}
			jQuery('#videoDetails-featuring .videoDetailsAttrVal').html(featuredArtists);
		}else
		{
			jQuery('#videoDetails-featuring').css('display', 'none');
		}
		
		//Genre
		if(videoJSON.primaryGenre && videoJSON.primaryGenre.id){
			jQuery('#videoDetails-genre').css('display', 'block');
			jQuery('#videoDetails-genre .videoDetailsAttrVal').html('<a class="red" href="'+MTVM.config.serverHostName+'/charts/numberOfViews/today/?genre='+videoJSON.primaryGenre.id+'">'+videoJSON.primaryGenre.name+'</a>');			
		}else
		{
			jQuery('#videoDetails-genre').css('display', 'none');
		}
		
		
		//change socialnetwork stuff	
		try{
		
				MTVM.util.socialNetwork.shareUrl	= MTVM.config.serverHostName+"/"+MTVM.lang.urls.artist+"/"+videoJSON.artists[0].alias				
				
				MTVM.util.socialNetwork.mesg = MTVM.lang.video.socialMesg.replace(/\[ARTISTNAME\]/, MTVM.util.escapeQuotes(videoJSON.artists[0].name));
				MTVM.util.socialNetwork.mesg = MTVM.util.socialNetwork.mesg.replace(/\[VIDEONAME\]/, MTVM.util.escapeQuotes(videoJSON.title));
				
				MTVM.util.socialNetwork.embed		= encodeURI("<embed src=\"http://media.mtvnservices.com/"+videoJSON.contentUri+"\" width=\"512\" height=\"319\" type=\"application/x-shockwave-flash\" flashVars=\"dist="+MTVM.config.serverHostName+"&#38;configParams="+MTVM.lang.embedConfigParams+"\" allowFullScreen=\"true\" AllowScriptAccess=\"always\"&gt;</embed&gt;<div style=\"margin:0; text-align:center; width:512px;font-family:Arial,sans-serif;font-size:10px;\"&gt;<a style=\"color:#000000;\" href=\""+MTVM.config.serverHostName+"/"+MTVM.lang.urls.artist+"/"+videoJSON.artists[0].alias+"\"&gt;"+MTVM.util.escapeQuotes(videoJSON.artists[0].name)+"</a&gt; | <a style=\"color:#000000;\" href=\""+MTVM.config.serverHostName+"\"&gt;"+MTVM.lang.site.name+"</a&gt;</div&gt;");

				//addthis config change
				if(typeof window.addthis_share != "object")
				{
					window.addthis_share = {}
				}
				window.addthis_share.title = MTVM.util.socialNetwork.mesg;
				window.addthis_share.url = MTVM.util.socialNetwork.shareUrl;
				
		}
		catch(e){MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateVideoInfo error updating social network "+e, 2);}


		//featured on ie:rockband AND update buyable		
		try{
			if(MTVM.config.countryCode == "us")
			{
				this.getFeaturedOnRockband();			
				$_WGPlayable.isVideoIdBuyable(videoJSON.id, "track", "buyButtonWrapper");
			}			
		}
		catch(e){MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateInfo rockband : failed :" + e, 2);}
		
		

		//add to playlist button
		
		addToPlayListButton = document.getElementById("playlistAddButtonDiv");
		if (addToPlayListButton!=null){
			$J(addToPlayListButton).next().remove();
			$J(addToPlayListButton).remove();
		}	
		MTVM.Playlist.domRenderButtonWithText(videoJSON.contentUri);
		
		
	}
	catch(e)
	{
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.updateInfo : failed :" + e, 2);		
	}
}


/*** Featured On Rockband ***/
MTVM.Playlist.VideoDetailsReloader.prototype.getFeaturedOnRockband = function()
{
	MTVM.log('MTVM.Playlist.VideoDetailsReloader.prototype.getFeaturedOnRockband init');
	try{		
		if(MTVM.Playlist.VideoDetailsReloader.rockbandJSON == null || MTVM.Playlist.VideoDetailsReloader.rockbandJSON == "") //checks if rockband data is in memory, reduces redundant hits
		{

			$J.ajax({			
				url: '/sitewide/xml/rockband.xml',
				type: 'GET',
				data: '',
				dataType: 'xml',
				timeout: 10000,
				error: function(){
					MTVM.log('MTVM.Playlist.VideoDetailsReloader.prototype.getFeaturedOnRockband : Error loading XML document', 2);
				},
				success: function(xml)
				{
					MTVM.Playlist.VideoDetailsReloader.rockbandJSON = $J.xml2json(xml); //reduces redundant hits

					for(var i=0; i<MTVM.Playlist.VideoDetailsReloader.rockbandJSON.mapping.length; i++)
					{
						if(MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON.id == MTVM.Playlist.VideoDetailsReloader.rockbandJSON.mapping[i].id)
						{
							jQuery('#videoDetails-featuredOn').css('display', 'block');
							jQuery('#videoDetails-featuredOn').html('Featured On <a href="'+MTVM.Playlist.VideoDetailsReloader.rockbandJSON.mapping[i].url+'" target="_blank"><img src="/sitewide/img/rockband.gif" border="0"></a>');
							break;
						}else{
							jQuery('#videoDetails-featuredOn').css('display', 'none');
						}
					}
				}
				});
		}else
		{
			for(var i=0; i<MTVM.Playlist.VideoDetailsReloader.rockbandJSON.mapping.length; i++)
			{
				if(MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON.id == MTVM.Playlist.VideoDetailsReloader.rockbandJSON.mapping[i].id)
				{
					jQuery('#videoDetails-featuredOn').css('display', 'block');
					jQuery('#videoDetails-featuredOn').html('Featured On <a href="'+MTVM.Playlist.VideoDetailsReloader.rockbandJSON.mapping[i].url+'" target="_blank"><img src="/sitewide/img/rockband.gif" border="0"></a>');
					break;
				}else{
					jQuery('#videoDetails-featuredOn').css('display', 'none');
				}
			}
		
		}
	}
	catch(e)
	{
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.prototype.getFeaturedOnRockband  failed "+e, 2);
	}
}

MTVM.Playlist.VideoDetailsReloader.prototype.hideAllDetails = function()
{
	$J('#videoDetails-thumbnail').html('');
	$J('#videoDetails').css('display', 'none');
	$J('#share').css('display', 'none');
	$J('#interact').css('display', 'none');
	$J('#contentBottomRow').css('display', 'none');	
}

MTVM.Playlist.VideoDetailsReloader.prototype.showAllDetails = function()
{	
	$J('#videoDetails').css('display', 'block');
	$J('#share').css('display', 'block');
	$J('#interact').css('display', 'block');
	$J('#contentBottomRow').css('display', 'block');	
}



/*************** VIDEO DataService **************/
MTVM.Playlist.VideoDetailsReloader.DataService = 
{
	videoMgid:	null,
	videoJSON:	"",
	
	get		: function(mgid)	
	{			
		MTVM.log("MTVM.playlist: MTVM.Playlist.VideoDetailsReloader.DataService.get: "+mgid);
		MTVM.Playlist.VideoDetailsReloader.DataService.videoMgid = mgid;
		MTVM.Playlist.VideoDetailsReloader.DataService.__loadData(mgid);
	},
	
	__loadData	: function(mgid)
	{
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.DataService loading data: "+mgid);
		try{
			$J.ajax({			
				url: '/sitewide/dataservices/videoInfo/getVideoInfo/',
				type: 'GET',
				data: "mgid="+mgid+"&showComments=false",
				dataType: 'json',
				timeout: 10000,
				error: function(){
					MTVM.log('MTVM.Playlist.VideoDetailsReloader.DataService : Error loading JSON document', 2);
				},

				success: function(data)
				{
					MTVM.Playlist.VideoDetailsReloader.DataService.__processData(data);
				}

			});
		}
		catch(e)
		{
			MTVM.log("MTVM.Playlist.VideoDetailsReloader.DataService  failed "+e, 2);
		}
	},
	

	__processData:	function(json)
	{
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.DataService processing data");
		
		try
		{
			MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON = json;			
			MTVM.EventsManager.broadcast("onVideoDetailsReloaderDataSerivceReady");
		}
		catch(e)
		{
			MTVM.log("MTVM.Playlist.VideoDetailsReloader.DataService processData failed "+e, 2); 
		}
	}
}




/*************** Next Airing Show Dataservice **************/
MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice =
{
	showJSON: {},
	
	seriesId: null,
	
	get		: function(seriesId)		
	{			
		MTVM.log("MTVM.playlist: MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice.get: "+seriesId);
		MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice.videoseriesId = seriesId;
		MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice.__loadData(seriesId);
	},
	
	__loadData	: function(seriesId)
	{
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice loading data: "+seriesId);
		try{
			$J.ajax({			
				url: '/sitewide/dataservices/videoInfo/getNextAiring/',
				type: 'GET',
				data: "seriesId="+seriesId+"&showComments=false",
				dataType: 'json',
				timeout: 10000,
				error: function(){
					MTVM.log('MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice : Error loading JSON document', 2);
				},

				success: function(data)
				{
					MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice.__processData(data);
				}

			});
		}
		catch(e)
		{
			MTVM.log("MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice  failed "+e, 2);
		}
	},
	

	__processData:	function(json)
	{
		MTVM.log("MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice processing data");
		
		try
		{
			MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice.showJSON = json;

			if(MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice.showJSON.date !="")
			{
				if(document.getElementById('videoDetails-series'))
				{
					var seriesTitle = MTVM.lang.playlist.series.replace('[SERIESNAME]', MTVM.Playlist.VideoDetailsReloader.DataService.videoJSON.seriesName);
					$J('#videoDetails-series .videoDetailsAttrName').html(seriesTitle);
					document.getElementById("videoDetails-series").style.display = "block";
				}
				
				$J('#videoDetails-nextAiring .videoDetailsAttrVal').html(MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice.showJSON.date);
				document.getElementById("videoDetails-nextAiring").style.display = "block";
			}
		}
		catch(e)
		{
			MTVM.log("MTVM.Playlist.VideoDetailsReloader.NextAiringDataservice processData failed "+e, 2); 
		}
	}
}
