$(function() {
	var t;
	var temporipetizione=800;
	
	
  $('#menuProdotti4 .catsec').hover(function() {
	//console.log("sono dentro");

      if ($('#menuProdotti4 .catsec#'+$(this).attr('id')+' li').length >= 2) {
    			t = setInterval( "slideSwitch('"+$(this).attr('id')+"','')", temporipetizione );
    	}	
  }, function() {
  		if ($('#menuProdotti4 .catsec#'+$(this).attr('id')+' li').length >= 2) {
  			clearInterval(t);
  	  	//slideSwitch($(this).attr('id'),'y');
    		$('#menuProdotti4 .catsec#'+$(this).attr('id')+' li').stop(true, true).removeClass('active');
    		$('#menuProdotti4 .catsec#'+$(this).attr('id')+' li:first').stop(true, true).addClass('active');		
		
  		}		
  });
});


function slideSwitch(idp, clear) {
	var temposlide=600;
	var $active = $('#menuProdotti4 .catsec#'+idp+' li.active');
	if ( $active.length == 0 ) $active = $('#menuProdotti4 .catsec#'+idp+' li').last();
	if (clear=="y")	{
    var $next = $('#menuProdotti4 .catsec#'+idp+' li').first();
    temposlide=0
  }
	else {
    var $next = $active.next().length ? $active.next() : $('#menuProdotti4 .catsec#'+idp+' li').first()
  }
		
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		 .addClass('active')
		 .animate({opacity: 1.0}, temposlide, function() {
			$active.removeClass('active last-active');
		 });
		 
}

