Writing jQuery functions that allow chaining
<p>I want to write some code that allows me to replace jQuery's animate function with one that does different things, but still allows me to call a secondary function on completion.</p>

<p>At the moment, I'm writing lots of code like this;</p>

<pre><code>if (cssTransitions) {
   $("#content_box").css("height",0);

   window.setTimeout(function() {
       secondFunction(); 
   }, 600);
} else {
    $("#content_box").animate({
        height:0
    }, 600, function() {                
        secondFunction();
    });
}
</code></pre>

<p>I'd much rather write a function that looks like this:</p>

<pre><code>function slideUpContent(object) {
    if (cssTransitions) {
         object.css("height",0);
         // Not sure how I get a callback here
    } else {
        $("#content_box").animate({
            height:0
        }, 600, function() {
        });
    }
}
</code></pre>

<p>That I could use like this:</p>

<pre><code>slideUpContent("#content_box", function(){
    secondFunction();
});
</code></pre>

<p>But I'm not sure how to get the functionality I need - namely a way to run another function once my one has completed.</p>

<p>Can anyone help my rather addled brain?</p>
