javascript wait til function is finished
<p>I have a javascript function that goes like this:</p>

<pre><code>$(document).keydown(function(e) {
    switch(e.which) {
        case 38:
            moveUp();
            break;
        case 40:
            moveDown();
            break;
    }
});
function moveDown() {
    $('element').animate({top: "100%"}, {duration: 1000 });
}
function moveUp() {
    $('element').animate({top: "-100%"}, {duration: 1000 });
}        
</code></pre>

<p>My question is how would I create a delay in the <code>keydown</code> function that tells it that it has to wait until the function <code>moveUp()/movedown()</code> is finished before calling the function again without creating a queue?</p>

<p>Thank you for all the advise, by the way, I cant use <code>setTimeout</code> because it would cause a delay on every initial function.</p>