$(document).ready(function() {
    // Prepare vote elements for nice voting!
    $('a.vote').click(vote_do);
});

function vote_do() {
    var re = /^vote_(\d+)_(inc|dec)$/i;
    $(this).attr('id').search(re);
    var story_id = RegExp.$1;
    var action = RegExp.$2;
    var tag = $(this).parent();
    $('a#vote_'+story_id+'_inc').hide();
    $('a#vote_'+story_id+'_dec').hide();
    $.ajax({
        url: '/ajax/vote/'+story_id+'/'+action,
        dataType: 'text',
        success: function (data, textStatus) {
            $('span#rating_'+story_id).html(data);
            // Create text in <span> with class 'rating_done'
            $('<span>Ваш голос учтен</span>').attr('class', 'rating_done').appendTo(tag);
        },
        error: function () {
            $('<span class=error>Ошибка при отправке данных на сервер</span>').attr('class', 'rating_done').appendTo(tag);
        }
    });

    return false;
}

