It might be worth seeing if bootstrap can help us simplify this code:
http://twitter.github.com/bootstrap/javascript.html#modals