$(document).ready(function() {
    $('select.rating').change(function() {
        rating = $(this).val();
        story = $(this).attr('id').split('-')[1];
        url = '/rate/' + story + '/' + rating + '/';
        $.get(url);
    });
    $('a.action-button').click(function(e) {
        e.preventDefault();
        clicked = $(this);
        id = clicked.attr('id');
        action = id.split('-')[0];
        story = id.split('-')[1];
        if (action == 'getoverit') {
                score = 1;
        } else if (action == 'sympathize') {
                score = 2;
        }
        url = '/sympathize/' + story + '/' + score + '/';
        $.get(url, function(data) {
            getoveritSelector = 'span#getoverit-count-' + story;
            sympathizeSelector = 'span#sympathize-count-' + story;
            $(getoveritSelector).html(data.get_over_it);
            $(sympathizeSelector).html(data.sympathize);
            clicked.parent().siblings().removeClass("selected");
            clicked.parent().addClass("selected");
        });
    });
});
