
function apply_commenter_data() {
    FB_RequireFeatures(["XFBML","Api"], function()
    {
        FB.Facebook.init(window.api_key, window.xd_receiver_url);

        // Get the current logged in user
        var session = FB.Facebook.apiClient.get_session();
        if (!session) return;
        var viewerId = session.uid;
        if (!viewerId) return;

        // Find the various FB users we're rendering
        var FBIds = new Array();
//        jQuery("fb:name").each(function() {
//            FBIds.push($(this).getAttribute("uid"));
//        });

        var nameTags = jQuery("fb\\:name");
	var nameTagsLength = nameTags.length;

	for(var i=0;i < nameTagsLength ; i++)
	{
		FBIds.push(nameTags[i].getAttribute("uid"));
	}

        // Highlight your comments
        jQuery(".comment-fb-" + viewerId).each(function() {
            $(this).addClass("comment-friend");
        });

        // Find friends and highlight theirs
        FB.Facebook.apiClient.fql_query("SELECT uid2 FROM friend WHERE uid1=" + viewerId + " AND uid2 IN (" + FBIds.join(',') + ")", function(result, ex)
        {
            for (var i = 0; i < result.length; i++) {
                jQuery(".comment-fb-" + result[i]["uid2"]).each(function() {
                    $(this).addClass("comment-friend");
                });
            }
        });

        // Hide the URL and "remember me" boxes
        jQuery('#comments-open-data').hide();
    });
}

function send_story(post_url, post_title, story_template_id) {
    FB_RequireFeatures(["Api", "Connect"], function()
    {
        FB.Facebook.init(window.api_key, window.xd_receiver_url);
        FB.Connect.get_status().waitUntilReady(function(status) {

var attachments = {'name':post_title,'href':post_url,'description':'I commented on this post on Bagsnob.'};
var actionLinks = null;//[{ "text": post_title, "href": post_url}];

FB.Connect.streamPublish(
	'',
attachments,
actionLinks,
null,
"What's on your mind?",
null,
false,
null);


        });
    });
}

function facebook_logout() {
    FB_RequireFeatures(["Api", "Connect"], function() {
        FB.Facebook.init(window.api_key, window.xd_receiver_url);

        // Get the current logged in user
        var session = FB.Facebook.apiClient.get_session();
        if (!session) return;
        var viewerId = session.uid;
        if (!viewerId) return;

        FB.Connect.logout();
    });
}

