Add AMD support

The title pretty much says it all. It adds AMD support reverting to browser global var if not on a AMD environment.