$(function() {
	// load images/bind behaviors for menu rollover
	PEPS.rollover.init();
	
	// fadeout flash messages on click
	$('.cancel').click(function() {
		$(this).parent().fadeOut();
		return false;
	});

	// fade out good flash messages after 3 seconds
	$('.flash_good').animate({opacity: 1.0}, 3000).fadeOut();
	
	$('#mikeyears a').click(function() {
	
		var imgUrl = "/img/mike/mike" + $(this).attr('rel') + ".jpg";
		
		$('#mikeframe #img').attr('src', imgUrl);
		$('#mikeframe #link').attr('href', imgUrl);
	
		$('#mikeyears a').each(function() {
			$(this).removeClass('off').addClass('on');
		});
	
		$(this).removeClass('on').addClass('off');
		
		return false;
	
	});
	
});

PEPS = {};

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

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

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