///////////////////////
//PRELOAD GIB OVERLAY//
///////////////////////
var gibOverlay = new Image(48, 48);
gibOverlay.src = "/images/gib-overlay.png";

/////////////////////////////////////////////////////////////////////////////////
//FUNCTION TO KEEP OPACITY CHANGE ON PRODUCT THUMBNAIL WHEN GIB OVERLAY APPEARS//
/////////////////////////////////////////////////////////////////////////////////
var origStyles = new Array();
var i = 0;

function keepGreenProdThumbFormat(caller, state)
{
	var prodThb = $(caller).parent().parent().siblings("a.subCatProdThb")
	var idx = $(".thbGreen").index($(caller).parent());
	switch(state)
	{
		case "on":
		$(prodThb).css({opacity : "1", color : "#333333"});
		break;
		
		case "off":
		$(prodThb).attr("style", "").attr("style", origStyles[idx]);
		break;
	}
}

//////////////////////////////////////////////////////////
//FUNCTION TO DISPLAY GIB OVERLAY ON GREEN PRODUCT THUMB//
//////////////////////////////////////////////////////////
function showGIB(caller)
{
	$(caller).css("display") == "none" ? $(caller).css("display", "block") : $(caller).css("display", "none");
}

////////////////////////////////
//FUNCTION TO SHOW CATEGORY AD//
////////////////////////////////
function showCatAd()
{
	$("#catAdImg").fadeIn(1000, function()
	{
		$("#catTagLine").show().css("opacity", "0").fadeTo(1000, 0.85);	
	});
}

/////////////////////////////////////////////////////////////////////////////////////////////////

$(document).ready(function()
{
	////////////////////
	//SHOW CATEGORY AD//
	////////////////////
	showCatAd();
	
	///////////////////////////////////////////
	//SHOW GIB OVERLAY ON GREEN PRODUCT THUMB//
	///////////////////////////////////////////
	if($(".thbGreen:eq(0)").length > 0)
	{
		$(".thbGreen").each(function()
		{
			var thbGreen = $(this).parent();
			var thbGreenLink = $(this).children("a");
			var sib = $(this).parent().siblings("a.subCatProdThb");
			
			$(thbGreenLink).mouseover(function(){showGIB(thbGreen)}).mouseout(function(){showGIB(thbGreen)});
			$(sib).mouseover(function(){showGIB(thbGreen)}).mouseout(function(){showGIB(thbGreen)});
		});
	}
	
	/////////////////////////////////////////////////////////////////////
	//KEEP OPACITY CHANGE ON PRODUCT THUMBNAIL WHEN GIB OVERLAY APPEARS//
	/////////////////////////////////////////////////////////////////////
	if($(".thbGreen:eq(0)").length > 0)
	{	
		$(".thbGreen").each(function()
		{
			origStyles[i] = $(this).parent().siblings("a.subCatProdThb").attr("style");
			$(this).children("a").mouseover(function(){keepGreenProdThumbFormat(this, "on")}).mouseout(function(){keepGreenProdThumbFormat(this, "off")});
			i = i + 1;
		});
	}
});
