$(function() {
	$('.banner_destaques').cycle({
	    fx:    'fade', 
	    speed: 2000,
	    timeout: 6000,
	    next:  '#nextBanner',
	    prev:  '#prevBanner' 
	 });

	$('#nextBanner').mousedown(function() {
		$(this).css("margin-top", "+=3");
		$(this).css("margin-right", "-=3");
	});

	$('#nextBanner').mouseup(function() {
		$(this).css("margin-top", "-=3");
		$(this).css("margin-right", "+=3");
	});

	$('#prevBanner').mousedown(function() {
		$(this).css("margin-top", "+=3");
		$(this).css("margin-left", "-=3");
	});

	$('#prevBanner').mouseup(function() {
		$(this).css("margin-top", "-=3");
		$(this).css("margin-left", "+=3");
	});
	
	var sel = null, prevSel = null;
	
	$(".nav_categorias_produtos > li ul").css("display", "none");

	var selector = ".nav_categorias_produtos > li h3 a";
	var hoverOverSpeed = 300;
	var hoverOutSpeed = 400;
	
	$(selector).hoverFadeColor({fadeFromSpeed:hoverOutSpeed, fadeToSpeed:hoverOverSpeed, color:"#FFFFFF", stopHoverAnimationOnOut: true});			
	
	$(selector).css({background:'none'}); //removes default CSS :hover effect				
	$(selector).backOpacity({background: 'transparent', opacity: '0'}); // Initiate default background opacity				
	$(selector).hover(
		
		function() {
			if (this === sel) return;
			$(this).siblings('div').stop().animate({'opacity':1},hoverOverSpeed); //fade out on hover
		},
		
		function() {
			if (this === sel) return;
			$(this).siblings('div').stop().animate({'opacity':0}, hoverOutSpeed); //fade in on mouseout
	
		}
	);

	if (categoriaProd) $(".nav_categorias_produtos").css("display", "none");
	
	$(".nav_categorias_produtos > li h3").each(function(index) {
		$(this).click(function(e){
			e.preventDefault();
			$(".nav_categorias_produtos > li ul").slideUp(hoverOverSpeed);					
			if (sel){
				prevSel = sel;			
				$(sel).hoverFadeColor("enable", true);
				$(sel).hoverFadeColor("out");
				$(sel).siblings('div').stop().animate({'opacity':0}, hoverOutSpeed);
			}

			sel = $(this).find("a").get(0);
			if (prevSel !== sel){						
				$(this).parent().find("ul").slideToggle(hoverOverSpeed);
				$(sel).hoverFadeColor("hover");
				$(sel).hoverFadeColor("enable", false);	
				$(sel).siblings('div').stop().animate({'opacity':1}, hoverOverSpeed);
			}else{
				sel = null;
				prevSel = null;
			}
		});

		if (categoriaProd && $(this).parent().attr("accordionIndex") == categoriaProd){						
			$self = this;
			var hoverOverSpeedTemp = hoverOverSpeed;
			hoverOverSpeed = 0;
			setTimeout(function(){
				$($self).click();
				hoverOverSpeed = hoverOverSpeedTemp;
				$(".nav_categorias_produtos").css("display", "block");
			}, 100);
		}
	});
});
