// JavaScript Document


$(document).ready(function(){
PEPS.rollover.init();
});


//Image Rollover
PEPS = {};
PEPS.rollover =
{
   init: function()
   {
      this.preload();
      $(".rollover").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() {
         $('.rollover').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_r' + src.match(/(\.[a-z]+)$/)[0];
   },
   oldimage: function( src )
   {
      return src.replace(/_r\./, '.');
   }
};




$(document).ready(function(){
						   
						   
/*  hides background line from last link  */


$("#leftnav a:last").css({'border' : 'none'});
$("#rightnav a:last").css({'border' : 'none'});

/*  sub categories display stuff  */


$(".subcat_wrapper").hide();
$("#insidecat .hideall").hide();

$(".seemore").click(function(){
	  $(this).next(".subcat_wrapper").slideToggle(500);
	  $(this).toggleClass("open");
	  $("#insidecat .hideall").hide();
	  $("#insidecat .viewall").show();
	});

$("#insidecat .viewall").click(function(){
	  $(".subcat_wrapper").slideDown(500);
	  $(".category .seemore").addClass("open");
	  $(this).hide();
	  $("#insidecat .hideall").show();
	});

$("#insidecat .hideall").click(function(){
	  $(".subcat_wrapper").slideUp(500);
	  $(".category .seemore").removeClass("open");
	  $(this).hide();
	  $("#insidecat .viewall").show();
	});


/*  freight pop up stuff  */

$(".popupbox").hide();

//this is the script for the close button. it will close whatever it is in
$(".popupbox .closefreight").click(function(){
	  $(this).parent().parent(".popupbox").fadeOut(200);
	  $(this).parent().parent().siblings().removeClass("active");
	});

$(".popupbox .cancel").click(function(){
	  $(this).parent().parent(".popupbox").fadeOut(200);
	  $(this).parent().parent().siblings().removeClass("active");
	});

$(".popup").click(function(){
	  $(this).next(".popupbox").fadeIn(200).siblings(".popupbox").fadeOut(200);
	  $(this).siblings().removeClass("active");
	  $(this).addClass("active");
	});



/*  product page tabs  */

$(".producttabs #desc").show();
$(".producttabs #specs").hide();
$(".producttabs #pack").hide();

$(".tabdesc").parent().addClass("active");


$(".tabdesc").click(function(){
		$(this).parent().addClass("active");
		$(this).parent().siblings().removeClass("active");
		$(".producttabs #desc").show();
		$(".producttabs #specs").hide();
		$(".producttabs #pack").hide();
	});

$(".tabspec").click(function(){
		$(this).parent().addClass("active");
		$(this).parent().siblings().removeClass("active");
		$(".producttabs #desc").hide();
		$(".producttabs #specs").show();
		$(".producttabs #pack").hide();
	});

$(".tabpack").click(function(){
		$(this).parent().addClass("active");
		$(this).parent().siblings().removeClass("active");
		$(".producttabs #desc").hide();
		$(".producttabs #specs").hide();
		$(".producttabs #pack").show();
	});


/*  knowledge base  */

$(".kbitem .description").hide();

$("#catlist li a").click(function () {
	$(this).addClass("active");
	$(this).parent().siblings().children("a").removeClass("active");
	});

$(".kbitem .title").click(function () {
	$(this).addClass("active");
	$(this).parent().siblings().children(".title").removeClass("active");
	$(this).next(".description").slideDown();
	$(this).parent().siblings().children(".description").slideUp();
	});

});