$(document).ready(function (){
    $('.comment_show_action').click(function () {
        $(this).parent().removeClass('hidden');
        $(this).remove();
        return false;
    });
    $('.comment_vote').click(function () {
        var target = $(this).siblings('.value');
        var message = $(this).siblings('.message');
        $.getJSON($(this).attr('href') + '/json', function(data) {
            if (data.status == 'Ok') {
                target.html(data.rank);
                message.html('Twój głos został zapisany!');
            }
            else if (data.status == 'AlreadyVoted') {
                message.html('Jeden głos na jeden komentarz!');
            }
            else if (data.status == 'SigninRequired') {
                message.html('Zaloguj się aby głosować!');
            }
        });
        return false;
    });
    $('.comment_remove').click(function() {
        var target = $(this).closest('li');
        var text = '<p style="text-align: center;">Komentarz został usunięty!</p>';
        $.getJSON($(this).attr('href') + '/json', function(data) {
            if (data.status == 'Ok') {
                target.empty();
                target.append(text).delay(1000).fadeOut(2000);
            }
            else {
                alert(data.status);
            }
        });
        return false;
    });
});


