Namespace("Nbcu.Sn.Rating");
Nbcu.Sn.Rating = function(){ this.constructor(); }
Nbcu.Sn.Rating.inherits(Nbcu);

Nbcu.Sn.Rating.method('setRating', function(callback, contentSSUniqueKey, contentID, contentURL, contentType, ratingValue)
{
	params = new Object();
	params.contentSSUniqueKey = contentSSUniqueKey || "";
	params.contentID = contentID || "";
	params.contentURL = contentURL || "";
	params.contentType = contentType || "";
	params.ratingValue = ratingValue || "";
	
	if (nbcu.config.getParam("facebookConnectEnabled") == "true" && nbcu.sn.session.isLoggedInToExternalPlatform('facebook'))
	{
		var videoWidgetEmbedSource = nbcu.app.scet.video.getWidgetEmbedSource();
		
		var videoURL = nbcu.util.common.encodeHtml(window.document.location);
		var videoTitle = unescape(nbcu.app.scet.video.getParam("assetTitle"));
		var ratingIndex = ratingValue;
		var videoDesc = unescape(nbcu.app.scet.video.getParam("assetDescription"));
		var videoThumb = nbcu.app.scet.video.getParam('assetThumbnailUrl');
		var userInfo = readCookie("external_platform_user_info");
		var userInfoArray = new Array();
		userInfoArray = userInfo.split("%7C");
		var userName = escape(userInfoArray[2]);
		userName = userName.replace("+"," ");

		//for DST tags
		var brandVar = "nbc";
		var ratingFeedDST = "?dst="+brandVar+"|fbconnect|feedstory|rating&__source="+brandVar+"|fbconnect|feedstory|rating";

		
		var attachment = 
			{
				"name" : userName+' rated '+videoTitle+ ' as ' +ratingIndex+ ' out of 5 stars.',
				"href" : videoURL+ratingFeedDST,
				"description" : videoDesc,
				"media" : 
					[{"type" : "video", 
						"video_src" : nbcu.util.common.encodeHtml(videoWidgetEmbedSource),
						"preview_img" : videoThumb,
						"video_link" : videoURL+ratingFeedDST,
						"video_title" : videoTitle}]
			}
			
		var action_links = [{"text" : "Browse More Videos", "href" : "http://www.nbc.com/video/"+ratingFeedDST}];
	
		embeddedPlayerManager.getPlayer(videoplayerDiv).hidePlayer();
		var callbackFunction = function() {
				embeddedPlayerManager.getPlayer(videoplayerDiv).unHidePlayer();
		};
		facebook_stream_publish('', attachment, action_links, '', null, callbackFunction, false);


		/*var form_bundle_id = nbcu.config.getParam("videoRatingFeedStoryId");
		var videoWidgetEmbedSource = nbcu.app.scet.video.getWidgetEmbedSource();
		
		var template_data = 
			{
				"videoTitle" : unescape(nbcu.app.scet.video.getParam("assetTitle")),
				"ratingIndex" : ratingValue,
				"videoURL" : nbcu.util.common.encodeHtml(window.document.location),
				"videoDesc" : unescape(nbcu.app.scet.video.getParam("assetDescription")),
				"video" : {
					"video_src" : nbcu.util.common.encodeHtml(videoWidgetEmbedSource),
					"preview_img" : nbcu.app.scet.video.getParam('assetThumbnailUrl'),
					"video_link" : nbcu.util.common.encodeHtml(window.document.location)
				}
			}
		
		embeddedPlayerManager.getPlayer(videoplayerDiv).hidePlayer();
		facebook_publish_feed_story(form_bundle_id, template_data, null, null, function() {
				embeddedPlayerManager.getPlayer(videoplayerDiv).unHidePlayer();
		});*/
	}

	return nbcu.api.call("setRating", params, "sn", "rating", "PROXY", "GET", callback);
});

Nbcu.Sn.Rating.method('getRatingByContent', function(callback, contentSSUniqueKey, contentID, contentURL, contentType)
{
	params = new Object();
	params.contentSSUniqueKey = contentSSUniqueKey || "";
	params.contentID = contentID || "";
	params.contentURL = contentURL || "";
	params.contentType = contentType || "";
	result = nbcu.api.call("getRatingByContent", params, "sn", "snas", "PROXY", "GET", callback);

	var data = new Array();
	data["avgRatingValue"] = jqN(result).find("ratingByContent>content>avgRatingValue").text();
	data["ratingCount"] = jqN(result).find("ratingByContent>content>ratingCount").text();

	return data;
});

Nbcu.Sn.Rating.method('getRating', function(contentID, contentType)
{
	result = nbcu.sn.rating.getRatingByContent(null, contentID, contentType);

	var data = new Array();
	data["ratingValue"] = jqN(result).find("ratingByContent>content>ratingValue").text();
	data["ratingCount"] = jqN(result).find("ratingByContent>content>ratingCount").text();

	return data;
});

Nbcu.Sn.Rating.method('defaultAlert', function()
{
	alert("Thank you for rating!");
});

Namespace("nbcu.sn.rating");
nbcu.sn.rating = new Nbcu.Sn.Rating();

