jquery bounce animation

HTML

<div id="bounce"></div>

CSS

#bounce {
    height: 100px;
    width: 100px;
    background-color: red;
    margin-top: 50px;
}

JavaScript

$("#bounce").click(function() {
    doBounce($(this), 50, '10px', 1000);   
});


function doBounce(element, times, distance, speed) {
    for(i = 0; i < times; i++) {
        element.animate({marginTop: '-='+distance},100)
            .animate({marginTop: '+='+distance},speed);
    }        
}