/* ################################################################# */
/*                                                                   */
/*  TITLE:        NBC_POST_FB.JS                                     */
/*  VERSION:      2.02                                               */
/*  LAST UPDATED: 06/02/10                                           */
/*  UPDATED BY:                                                      */
/*                                                                   */
/*  NAMESPACE:                                                       */
/*                                                                   */
/*  PUBLIC FUNCTIONS:                                                */
/*                                                                   */
/*  PREREQUISTES:                                                    */
/*                                                                   */
/* @release 2009-10-26 - vicky                                       */
/* ################################################################# */

  $(document).ready(function() { 
  $(".postToFBArticlePage").click(function() {

     nbc.omniture.shareOption = "Facebook";
   // alert(nbc.omniture.shareOption);
     G.doPixelTracking(90);
     if (nbc.omniture.pageType == "vertical_blog") {
     	postFBDataForFeastBlogs(this);
     }
     else {
      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;
	      var userAction = "mood_voted";
	      U.log(userAction);
	     postToFacebookArticle(commtext, userAction);
	     }); 
});  
  function postToFacebookArticle(commentTxt, userAction) {
// publish to Facebook
   U.log("in publish");

   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;
	     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;   
   }
       
  var imagesArray2 ={};
   imagesArray2["src"]=nbc.fbparamshare.contentThumbUrl;
   imagesArray2["href"]=nbc.fbparamshare.contentUrl;
   U.log(imagesArray2['src']+" "+imagesArray2['href']);
   templateData_site_url = "http://" + nbc.domain+"/?__source=Facebook_Action_Link";
   templateData_site_name = nbc.host;
   templateData_comment = commentTxt;

   //facebook_publish_feed_story(nbc.fbparamshare.bundleId, templateData);
 
   var shareFB = {};

   var caption = templateData_user_action;

    
   /* FEAST setting */
   U.log(nbc.section);
   if (nbc.section == "feast") {
	   if (templateData_content_url == "false?__source=Facebook") {
		   templateData_content_url = $("#contentIdForTwitter").text();
	   }
	   
	   U.log(templateData_content_url);
       checkItOut = "Check it out at Feast on "+templateData_site_name;
       var defaultThumbImg = nbc.mediaDomain+"/designimages/75*75/no-image.gif";
       U.log(defaultThumbImg);
       U.log(nbc.fbparamshare.contentThumbUrl);
       if (nbc.fbparamshare.contentThumbUrl == defaultThumbImg) {
    	  imagesArray2["src"]="http://media.nbclocalmedia.com/designimages/logo-feast-fb.gif";
       }
   }
   
   shareFB.attachment = {media: [{'type':'image', 'src':imagesArray2["src"], 'href':imagesArray2["href"]}],
		   name: templateData_content_title, 
		   href: templateData_content_url,
		   caption: nbc.host,
		   description: nbc.fbparamshare.summary
   };
   
   if (userAction == "mood_voted") {
	   var checkItOut = "Check it out on "+templateData_site_name;
	   var propertyUrl = templateData_content_url+"_Property";
	   U.log("TEST USER ACTION "+templateData_user_action);
	   var captionMood = templateData_user_action;
	   shareFB.attachment = {media: [{'type':'image', 'src':imagesArray2["src"], 'href':imagesArray2["href"]}],
			   name: templateData_content_title, 
			   href: templateData_content_url,
			   caption: nbc.host,
			   description: nbc.fbparamshare.summary
	   };
   }
   
   if (nbc.section == "feast") {
	   if (nbc.subsection =="search") {
		   imagesArray2["href"]=nbc.fbparamsharesearchdata.listUrl;
		   searchTitle="";
		   if (nbc.fbparamsearch.neighborhood !="") {
		      searchTitle = searchTitle + nbc.fbparamsearch.neighborhood;
	       }
	      if (nbc.fbparamsearch.location !="") {
	    	  if (searchTitle !="")  searchTitle = searchTitle + ", " + nbc.fbparamsearch.location;
	    	  else searchTitle = nbc.fbparamsearch.location;
	       }
		   if (nbc.fbparamsearch.cuisine !="") {
			   if (searchTitle!="")  searchTitle = searchTitle + ", " + nbc.fbparamsearch.cuisine;
			   else searchTitle = nbc.fbparamsearch.cuisine;
		    }
		    if (nbc.fbparamsearch.price !="") {
		    	if (searchTitle!="")  searchTitle = searchTitle + ", " + nbc.fbparamsearch.price;
		    	else searchTitle = nbc.fbparamsearch.price;
			}
		    if (nbc.fbparamsearch.keyword !="") {
		    	if (searchTitle!="")   searchTitle = searchTitle + ", " + nbc.fbparamsearch.keyword;
		    	else searchTitle = nbc.fbparamsearch.keyword;
			}
		    searchTitle = searchTitle + " | Feast | "+ nbc.cityName;
		    searchDescription = "The first word and final score on " + nbc.cityName + "&#39;s restaurant scene, featuring videos, photos, news, commentary and the definitive powerscore index, Feast Rank.";
		   shareFB.attachment = {media: [{'type':'image', 'src':imagesArray2["src"], 'href':imagesArray2["href"]}],
				   name: searchTitle, 
				   href: nbc.fbparamsharesearchdata.listUrl,
				   description: searchDescription
		   };
	   }
	  
   }
   
    var commentActionText = "Get Local";
    
    if (nbc.section == "feast") {
       commentActionText = "More From Feast";
       templateData_site_url = nbc.fullDomain + "/feast/?__source=Facebook_Action_Link";
    }
    shareFB.action_links = [{ "text": commentActionText, "href": templateData_site_url}]; 
    U.log("action links "+commentActionText + " "+templateData_site_url);
    if (userAction == "mood_voted") {
    	templateData_comment = templateData_user_action;
    }   

   if (nbc.section == "feast") {
     templateData_comment="";
     if (nbc.subsection =="restaurant-list") {
		   imagesArray2["href"]=nbc.fbparamsharelist.listUrl;
		//   alert(imagesArray2["src"]);
		   shareFB.attachment = {media: [{'type':'image', 'src':imagesArray2["src"], 'href':imagesArray2["href"]}],
				   name: nbc.fbparamsharelist.listTitle, 
				   href: nbc.fbparamsharelist.listUrl,
				   description: nbc.fbparamsharelist.listDesc
		   };
	   }
  }

    if ((nbc.section == "feast")  && (nbc.subsection =="restaurant-list")) {
    	 publish2 = {
    		     method: 'stream.publish',
    		     message: templateData_comment,
    		     attachment: shareFB.attachment,
    		     action_links: shareFB.action_links,
    		     user_prompt_message: 'Share your thoughts about '+nbc.fbparamsharelist.listTitle,
    		     display:"popup"
    		   };
    	
    }
    
    else if ((nbc.section == "feast")  && (nbc.subsection =="search")) {
    	 publish2 = {
    		     method: 'stream.publish',
    		     message: templateData_comment,
    		     attachment: shareFB.attachment,
    		     action_links: shareFB.action_links,
    		     user_prompt_message: 'Share your thoughts about '+searchTitle,
    		     display:"popup"
    		   };
    }
    else {
       	
    	userPromptMessageText = "";
    	if (nbc.fbparams) {
    		userPromptMessageText = nbc.fbparams.contentTitle;
    	}
    	else {
    		userPromptMessageText = nbc.fbparamshare.contentTitle;
    	}
    	U.log("TEST: "+ templateData_comment + " "+userPromptMessageText);
    	  publish2 = {
    			     method: 'stream.publish',
    			     message: templateData_comment,
    			     attachment: shareFB.attachment,
    			     action_links: shareFB.action_links,
    			     user_prompt_message: 'Share your thoughts about '+userPromptMessageText,
    			     display:"popup"
    			   };
    	
    }
		FB.ui(publish2, completedPublish2);
	  
		function completedPublish2() {
		  U.log("successfully posted data.");
		}
		
    //facebook_stream_publish_feed_story(shareFB, false);
		
}
  
 
 
 
 
 
 
 
 
 
 
 
 

