Fix glitch on resize, get rid of globals, switch to jquery 'on' instead of 'live'