Only initialize the various elements if they are in the dom.
Use uniformingly jQuery instead of $