Update engine.js

Changed access to window and document