/* ################################################################# */
/*                                                                   */
/*  TITLE:        NBC_POST_FB.JS                                     */
/*  VERSION:      2.00                                               */
/*  LAST UPDATED: 9/16/2009                                          */
/*  UPDATED BY:                                                      */
/*                                                                   */
/*  NAMESPACE:                                                       */
/*                                                                   */
/*  PUBLIC FUNCTIONS:                                                */
/*                                                                   */
/*  PREREQUISTES:                                                    */
/*                                                                   */
/* @release 2009-10-26 - vicky                                       */
/* ################################################################# */

  $(document).ready(function() { // this is dangerous not to coordinate these events with a manager.
  $(".postToFBArticlePage").click(function() {
     nbc.omniture.shareOption = "Facebook";
   // alert(nbc.omniture.shareOption);
     G.doPixelTracking(90);
      var commtext = nbc.fbparamshare.summary;
      var userAction = nbc.fbparamshare.contentType;
      U.log(userAction);
     postToFacebookArticle(commtext, userAction);
     }); 
  
  
  $(".postToFBMood").click(function() {
	  U.log("post to mood ");
	     nbc.omniture.shareOption = "Facebook";
	   // alert(nbc.omniture.shareOption);
	     G.doPixelTracking(90);
	      var commtext = nbc.fbparamshare.summary;
	      U.log("mood status "+nbc.fbparamshare.moodStatus);
	      var userAction = "mood_voted";
	      U.log(userAction);
	     postToFacebookArticle(commtext, userAction);
	     }); 
});  
  function postToFacebookArticle(commentTxt, userAction) {
// publish to Facebook
   U.log("in publish");
   var templateData = {};
   templateData.user_action = "";
   templateData.link_action ="";
   if (userAction == "article") {
      templateData.user_action = "just read";
      templateData.link_action ="Read More";
   }
   else if (userAction == "gallery") {
      templateData.user_action = "just looked at";
      templateData.link_action ="View It";
   }
   else if (userAction == "video_release") {
      templateData.user_action = "just watched";
      templateData.link_action ="Watch It";
   }
   else if (userAction == "debate") {
     templateData.user_action = "debates: Just voted on";
     templateData.link_action ="debates: Just voted on";
   }
   else if (userAction == "mood_voted") {
              var moodValueCookie = U.readCookie('moodValue');
             U.log(moodValueCookie);
	     templateData.user_action = "is "+moodValueCookie+" at ";
	     templateData.link_action ="Read more";
	   }
   else {
         templateData.user_action = "just read";
        templateData.link_action ="Read More";
   }
   templateData.content_url = nbc.fbparamshare.contentUrl; 
   templateData.content_title = nbc.fbparamshare.contentTitle;
   if ((userAction == "mood_voted") && (nbc.fbparamshare.moodStatus !="")) {
	 templateData.content_title = nbc.fbparamshare.moodStatus;   
   }
     
  U.log(nbc.fbparamshare.bundleId+" "+templateData.content_url+" "+templateData.content_title);
  var imagesArray ={};
  var imagesArray2 ={};
    imagesArray2["src"]=nbc.fbparamshare.contentThumbUrl;
   imagesArray2["href"]=nbc.fbparamshare.contentUrl;
U.log(imagesArray2['src']+" "+imagesArray2['href']);
   imagesArray[0]= imagesArray2;
   templateData.images=imagesArray;
   templateData.site_url = "http://" + nbc.domain;
   templateData.site_name = nbc.brand;
   templateData.comment = commentTxt;
   U.log("templateData.comment = "+templateData.comment+" nbc.fbparamshare.bundleId = "+nbc.fbparamshare.bundleId+" templateData.content_url = "+templateData.content_url+" templateData.content_title ="+templateData.content_title+" templateData.site_url="+templateData.site_url+" templateData.site_name ="+templateData.site_name+ " templateData.user_action="+templateData.user_action+" templateData.link_action="+templateData.link_action);
   facebook_publish_feed_story(nbc.fbparamshare.bundleId, templateData);
}
 
