$(function() {
    $('.votes a').click(function(){
    	var voteButton = $(this);
    	var score = voteButton.parent().find('.score');

    	var scoreWidth = score.width();

    	score.animate({width: '1px', opacity: 0}, function() {
            $.getJSON(voteButton.attr('href'), function(data) {
                if (data.success) {
                	if (voteButton.hasClass('vote-up')) {
                		score.text(parseInt(score.text()) + 1);
                	} else {
                		score.text(parseInt(score.text()) - 1);
                	}
                } else {
                    if (data.redirect != undefined) {
                        location.href = data.redirect;
                    }
                }

            	score.animate({width: scoreWidth, opacity: 1}, function() {
            		alert(data.message);
            	});
            });
    	});

        return false;
    });
});
