I know douglas crockford says to put all var declarations at the tops of functions, but I don't think it really matters much in practice, and in many cases - like this one - leads to lots of extra unnecessary SLOC.  If you want to do it this way that's fine though.