How do I use this javascript correct with wordpress?

Why not use CSS? Cross-browser example here: http://www.karlhorky.com/2012/06/cross-browser-image-grayscale-with-css.html