Script optimisation

Includes:
- inclusion of r.js for optimising (combining & minifying) the scripts
- changes to js code to make it compatible with r.js
- rake tasks to run r.js and hook it into the build/deploy process