// ======================================================================================
// Custom Rollover Script
// Notes:
//      - Include jQuery library on pages.
//      - Add class="rollOver" to any image you want to swap.
//      - Create the hover version as same name with "_hov" at end of filename.
//          Ex: myImage.jpg / myImage_hov.jpg
//      - Add an empty DIV to the page with id="rolloverText"
//          <div class="rolloverText"></div>
// ======================================================================================
$(document).ready( function()
{
   WRB.rollover.init();
});

WRB = {};

WRB.rollover =
{
   init: function()
   {
      this.preload();
     
      $(".rollOver").hover(
         // Mouse Over
         function () { 
            $(this).attr( 'src', WRB.rollover.newimage($(this).attr('src')) );
            $("#rolloverText").html($(this).attr( 'title'));
         },
         // Mouse Out
         function () { 
            $(this).attr( 'src', WRB.rollover.oldimage($(this).attr('src')) ); 
            $("#rolloverText").html("");
         }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.rollOver').each( function( key, elm ) { $('<img>').attr( 'src', WRB.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_hov' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/_hov\./, '.');
   }
};