// http://peps.ca/blog/easy-image-rollover-script-with-jquery/

$(document).ready( function()
{
   PEPS.rollover.init();
});

PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();
      $('.peps_rollover').mouseover( this.over );
      $('.peps_rollover').mouseout( this.out );
   },

   preload: function()
   {
      $('.peps_rollover').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
   },
   
   over: function()
   {
      $(this).attr('src', PEPS.rollover.newimage( $(this).attr('src') ));
   },
   
   out: function()
   {
      $(this).attr('src', $(this).attr('src').replace(/_hover/, '') );
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_hover' + src.match(/(\.[a-z]+)/)[0];
   }
}
