Cleanup of javascript file to make it jshint-compliant

I manually fixed some issues with non-declared variable, assignments in return statements etc. which made jshint fail.
This is neccessary, when your deployment process requires jshint-valid javascript files.

I also ran Google's js tool "fixjsstyle" to automatically clean up the file.