/**
 * @author obaid
 */
function facebook_publish_feed_story(form_bundle_id, template_data) {
  // Load the feed form
	FB.ensureInit(function() {
		//FB.Connect.showFeedDialog(form_bundle_id, template_data);
		//debugger;
		FB.Connect.showFeedDialog(form_bundle_id, template_data, null, null, FB.FeedStorySize.shortStory, FB.RequireConnect.promptConnect);
  });
};

function publishUserReviewNotification(data, isLoggedInFB) {
	if(isLoggedInFB) {
		templateId = user_review;
		facebook_publish_feed_story(templateId, data);
	}
}

function postJoinFeed(data, isLoggedInFB) {
	if(isLoggedInFB) {
		templateId = user_joins;
		facebook_publish_feed_story(templateId, data);
	}
}

function postAdded(data, isLoggedInFB) {
	if(isLoggedInFB) {
		templateId = user_added;
		facebook_publish_feed_story(templateId, data);
	}
}

function doLike(data, isLoggedIn, isLoggedInFB) {
	if (isLoggedInFB) {
		templateId = user_likes; //"62771217462";
		facebook_publish_feed_story(templateId, data);
	}
	if(!isLoggedIn) {
		$("#usermsg").html("You need to be logged in to use this feature.");
		$("#usermsg").fadeIn('slow').animate({opacity: 1.0}, 3000).fadeOut('slow', function() {  });
	}
	else {
		var bId = data.listing_id;
		
		$.ajax({
		   type: "POST",
		   data: "",
		   url: baseURL + "ajax/addtofave/"+bId,
		   success: function(msg){
		     	var r = msg;
				$("#ilike").addClass("alreadylikes");
				$("#ilike").onclick = function() {};
				$("#likecount").html(parseInt($("#likecount").text()) + 1);
				$("#usermsg").html("Listing has been added to your likes.");
				$("#usermsg").fadeIn('slow').animate({opacity: 1.0}, 3000).fadeOut('slow', function() {  });
		   }
		 });
		 
	}

}

function facebook_prompt_permission(permission) {
  FB.ensureInit(function() {
    FB.Connect.showPermissionDialog(permission);
  });
}

function facebook_hide_permission_request(elem) {
	$(elem).hide();
	$(elem).removeClass("fb_perm");
	if($(".fb_perm").length == 0) {
		$('#fb_settings_block').hide();
	}
}

