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 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();
