/**
 * clap.js
 * 
 * 拍手機能
 *
 */
(function(){
    /*
     * コンストラクタ
     */
    var Clap = function () {
    }
    
    /*
     * クラス名、メソッド定義
     */
    Clap.prototype = {
        add : function (user_comm_id) {
            $.ajax({
                   type: 'POST',
                   url: '/vote/clap',
                   data: "&user_comm_id=" + user_comm_id,
                   success: $clap.add_after
                   });
        },

        add2 : function (comment_id, vote_id) {
            $.ajax({
                type: "POST",
                url: '/vote/clap',
                data: "&comment_id=" + comment_id + "&vote_id=" + vote_id,
                success: function(msg){
                    if (msg.match(/^success/)) {
                        $('#clap_count_' + comment_id).text(parseInt($('#clap_count_' + comment_id).text()) + 1);
                        //$('#clap_response_' + comment_id).remove();
                    }
                }
                });
        },

        add_after : function (text , status) {
            if (status == 'success') {
                var clap_object = eval( "(" + text + ")" );
                $('#clap_count_'+clap_object.user_comm_id).text(clap_object.clap_count);
                $('#clap_response_'+clap_object.user_comm_id).remove();
            }
        }

    };
    // ファイルロード時にグローバルに自身のクラスを生成
    $clap = new Clap();
})();

/**
 * 初期化
 */
$(function() {
});
