Complete rewrite using jQuery.