Allow AMD compilation/loading

Added checks for module.exports and define.amd.

Diff looks horrendous, but it's nearly all indenting from wrapping the tim definition.

Just thought I'd chuck this your way, since I've done it. Feel free to ignore.

A.