PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload(); //preload rollover images
      this.setcurrentpage(); //set image for current page to hover
     
      //bind hover function to those with ro class
      $(".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 )
   {
	//change to rollover image (if not already in rollover state)
	if(src.indexOf("_o.gif") == -1){
		return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
	}	
	else{
		return src;
	}
   },

   oldimage: function( src )
   {  
	//get current pagename
	strCurrPage = this.getcurrentpage();

	//change back to original state (if not the current page)
	if(src.indexOf(strCurrPage) == -1) {
     	 	return src.replace(/_o\./, '.');
	}
	else{
		return src;
	}
   },

   setcurrentpage: function()
   {
	//puts the image/link to the current page in the hover state
        strPg = this.getcurrentpage();
	$("#" + strPg).attr('src', PEPS.rollover.newimage( $("#" + strPg).attr('src') ));
   },

   getcurrentpage: function()
   {
	strURL = location.href; 	
	strPage = strURL.substring(strURL.lastIndexOf("\\")+1,strURL.lastIndexOf("\."));
	strPage = strURL.substring(strURL.lastIndexOf("\/")+1,strURL.lastIndexOf("\."));


	if(strPage.indexOf("\.") !=-1) {
		strPage = "index";
	}

	return strPage;
   }

};
