Rewrote some of the content cribbed from jQuery.