added all code from http://jsfiddle.net/moldcraft/2wfYm/30/show/