I think it would make more sense to have two separate functions, one for tearing down the UI and one for rebuilding it. Or at least pass the current visibility to swapInnerHTML. I'd hate for us to accidentally get out-of-sync and tear the UI down when the app is visible!

I think it would also make the code a little clearer.