jQuery/Javascript NaN when doing addition on number
<p>I'm attempting to create a simple link scroller but run into some trouble working out the current position.</p>

<p>Basically, in my code I've initialised the currentPos variable outside of the function. Then try to add 1 to it but I'm getting some erratic behaviour. Sometimes getting NaN.</p>

<p>This is on a localhost xampp installation, the same code works fine in jsfiddle so I can't understand it.</p>

<p>jsfiddle: <a href="http://jsfiddle.net/w654X/" rel="nofollow">http://jsfiddle.net/w654X/</a></p>

<p>My code is below, any help would be greatly appreciated.</p>

<pre><code>var currentPos = 1;

$('#test').click(function() {
    // exit if animation is already playing
    if ($(':animated').length) {
        return false;
    }

    height = $('#inner').height();
    noOfLinks = height / 53;
    lastPos = noOfLinks - 4;

    alert(currentPos);

    if (currentPos != lastPos) {
        $('#inner').animate({
            marginTop: "-=106px"
        });
    } 
    else {
        $('.arrow-up').hide();
    }

    currentPos += 1;
});
</code></pre>
