Need to figure out this upvote/downvote edge case
<p>I've been working on this upvote/downvote problem and I keep running into 3 problems.</p>

<p>Code:</p>

<pre><code>$(function() {

$('button').click(function(e){

    e.preventDefault();

    var $this = $(this),
        $container = $(this).parent(),
        $buttons = $container.children('button'),
        $count = $container.children('.count'),
        was = $container.data('was');

    // 0 case
    if ($this.is('.up')) {
        if (was === 0 || $this.is('.active')) {
            vote = 0;
        } else {
            vote = 1;
        }
    } else {
        vote = -1;
    }

    if ( was + vote &lt; 0 ) {
        $this.toggleClass('active');
        return false;
    }

    if( $this.hasClass('active') ){
        $this.toggleClass('active');
        $count.text( was );
    } else {
        if( $buttons.filter('.active').length ){
            $buttons.toggleClass('active');
        } else {
            $this.toggleClass('active');
        }
        $count.text( was + vote );
    }

});

});
</code></pre>

<p>Live Demo : <a href="http://jsfiddle.net/TV7G4/3/" rel="nofollow">jsfiddle</a> ​</p>

<p>I've labeled each case in the demo (6 cases total)</p>

<p>Problems:</p>

<ul>
<li><p>Case #1: If there is an active class on it and it originally was (data-was) 0, then clicking down should add an active class to down turning it red and keeping the count at 0.</p></li>
<li><p>Case #2: If the active class is on the down button and the original score was (data-was) at 1, then the active class should go on up, and the count should go to 3.</p></li>
<li><p>Case #3: If there is an up class on the button and the original score was (data-was) 1, then clicking down should make it go to 0 and put an active class on down, clicking up should make it go to 0 removing the active class from up, and clicking up with an active class on down should take it to back to 1.</p></li>
</ul>

<p>Cases #4 - #6 all behave normally, so if its not clear what the problems are, they should all behave like that, but <strong><em>never</em></strong> go below 0. </p>

<p>This keeps getting kind of complex, so I'm debating just showing the actual returned score from the ajax request, but I don't want any latency between clicks, so that's why I'm approaching it this way.</p>
