MAJOR js code re-org.  Ty Doug Crockford.

One day, maybe we could even pass JSLint...