/*
**	jQuery Image Rollover script
**
**	Usage: 	any image with class '.ro' will automatically become a rollover
** 			file naming example:
**			off		-	image.jpg
**			on		-	image_on.jpg (set through PHP but preserved here)
**			hover 	-	image_h.jpg
**/
$(document).ready( function()
{
   PEPS.rollover.init();
});

PEPS = {};

PEPS.rollover = 
{
   init: function()
   {
      this.preload();
      
      $(".ro").hover(
         function () { $(this).attr( 'rel', $(this).attr('src')); $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );}, 
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('rel')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   { 
	  src=src.replace('_on.', '.');
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_h' + src.match(/(\.[a-z]+)$/)[0]; 
   },

   oldimage: function( src )
   { 
      return src.replace(/_h\./, '.'); 
   }
};