You might be able to simplify this down a bunch with the jQuery `toggle()` method, which does precisely this (hides if already shown, and shows if currently hidden).