$(document).ready( function()
{
	PEPS.rollover.init();
});

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 ){
		var cleanSrc = src.replace(/_o/, ''); // Original src cannot have '_o' in the file name
		var srcLength = cleanSrc.length;
		var coreLength = srcLength - 4; // length of string with out the '.jpg, .png, .gif, etc'
		var srcCore = cleanSrc.substr(0,coreLength); // get the stripped src
		var srcSuffix = cleanSrc.substr(coreLength,4); // get the suffix '.jpg, etc'
		return srcCore + '_o' + srcSuffix;
		//return cleanSrc.substring( 0, cleanSrc.search(/(\.[a-z]+)/) ) + '_o' + cleanSrc.match(/(\.[a-z]+)/)[0];
	},
	
	oldimage: function( src ){ return src.replace(/_o/, ''); }
};
