var selfFlag = 0;

/**
 * PEPS ROLLOVER FUNCTION
 **/

PEPS = {};
PEPS.rollover = 
{
   init: function()
   {
      this.preload();
      
      $(".ro").children("img").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').children("img").each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   { 
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '1' + src.match(/(\.[a-z]+)$/)[0]; 
   },

   oldimage: function( src )
   { 
      return src.replace(/1\./, '.'); 
   }
};

$(function(){
   PEPS.rollover.init();
   
	if(scripts_isIE6) $(document).pngFix();

	$("a[rel^='lightbox']").prettyPhoto({
			animationSpeed: 'slow',
			padding: 40,
			opacity: 0.85,
			showTitle: false,
			allowresize: true,
			counter_separator_label: '/',
			theme: 'light_rounded'
	});

   $("#featuredHome").animate({
      "bottom": "-4px", "opacity": 1
    }, 700);
    
    
   $("li.navItem").mouseover(function(){
      $(this).css("background-color","#ed1c24");
   }).mouseout(function(){
      $(".navItem").css("background-color","transparent");
   });
    

   // ROLLOVERS

   $("a.ro2").mouseover(function(){

	var imgArr = $(this).children("img").attr("src").split(".");
	var imgPart1 = imgArr[0];
	var imgPart2 = imgArr[1];
	//alert(imgPart1 + " " + imgPart2);
	if(imgPart1.lastIndexOf("2") == -1){
	   $(this).children("img").attr("src",imgPart1+"1."+imgPart2);
	   selfFlag = 1;
	}else{
	   selfFlag = 0;
	}

  }).mouseout(function(){
    if(selfFlag == 1){
    	var imgOut = $(this).children("img").attr("src").replace(/1/,"");
	   $(this).children("img").attr("src",imgOut);
	   selfFlag = 0;
	}
  });

});
