// JQuery rollover script found at http://peps.ca/blog/easy-image-rollover-script-with-jquery/
$(document).ready( function()
{
   PEPS.rollover.init();
});

PEPS = {};

PEPS.rollover = 
{
   init: function()
   {
      this.preload();
      
      // navigation
      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
      // collection thumbnails
      $(".ro2").bind('mouseenter',function() {
          current_image = $(this);
          $(".ro2").css('opacity',1);
          $(this).css('opacity',0.5);
      });
      // collection scrollable
      $(".ro3").live('mouseenter', function() {
          currentsrc = $(this).attr('src');
          $(this).attr('src', PEPS.rollover.newimage( PEPS.rollover.oldimage(currentsrc)));
      });
      $(".ro3").live('mouseleave', function() {
          currentsrc = $(this).attr('src');
          $(this).attr('src', PEPS.rollover.oldimage(currentsrc));
      });
   },

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

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

$(".ro,.ro3").click(function(){
    $(this).trigger('mouseleave');
});