Java script Preload Gif

I found this java script, and what i wanted it to do is preload a GIF i have. the script im talking about is the second one
DHTML Kitchen - GIF preloader

im not excatly sure where im supposed to put the script or how to change their gif to one that i have

<script type="text/javascript">
   // <![CDATA[
     function loadSnoopy(){
         var snoopyOver = new Image();
         snoopyOver.src = "img/peanuts/snoopyOver.gif"; //<---This is where you want to change the image and path to your image.
     }
   // ]]>
  </script>

<body onload="loadSnoopy()"> //<--- Then replace your page's body tag with this and you should then have your image preloaded