(function(){
    jQuery.fn.fjFBLikeCount = function(options) {
        var options =
            jQuery.extend({
                format: 'いいね : {like_count}, シェア : {share_count}, コメント : {comment_count}, 合計 : {total_count}',
                url: location.href
            }, options);

        var self = this;
        var query = 'https://api.facebook.com/method/fql.query?query=';
        query += encodeURIComponent('SELECT share_count, like_count, comment_count, total_count FROM link_stat WHERE url = "' + options.url + '"');
        query += '&format=json&callback=?';
        jQuery.getJSON(query, function(rows, status) {
            var html = options.format;
            html = html.replace(/\{like_count\}/, rows[0].like_count);
            html = html.replace(/\{share_count\}/, rows[0].share_count);
            html = html.replace(/\{comment_count\}/, rows[0].comment_count);
            html = html.replace(/\{total_count\}/, rows[0].total_count);
            self.html(html);
        });
    }
})(jQuery);

