The first bit could be done directly in CSS, no?