Adding AMD support

This patch adds support for [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD). I've tested the change on a private codebase running require.js, and it works a treat!

Let me know if you have any questions.