Copied code and demo from http://www.thefutureoftheweb.com/blog/adddomloadevent