﻿var timemenu = setTimeout("", 200 );
var aperto;
var nulla;
var $elemento;
$j(function(){
	$j("#nav li").hover(function()
		{

			if(($j("div",this).attr('id') != nulla) && ($j("div",this).attr('id') != aperto))
			{
				clearTimeout(timemenu);
				nasconditutto();
				aperto = $j("div",this).attr('id');
				$elemento = $j("ul",this);
				timemenu = setTimeout("mostra()", 625 );
			} else if ($j("div",this).attr('id') == nulla)
			{
				nasconditutto();
			}
		}, function()
		{
			//alert('esce');
			clearTimeout(timemenu);

			$elemento = $j("ul",this);
			timemenu = setTimeout("nascondi()", 500 );
	});
	
	$j("#nav li ul").hover(function() {
		clearTimeout(timemenu);							
	}, function()
	{
		nascondi();
	});
	

	$j("#nav li img").each(function(){ 	
		//$j(this).hide("slow");
		$j(this).bind("click", function() {
			//alert('fds '+$j(this).attr('src'));
			$elemento = $j(this).next('ul');
			mostra();

		});
	});
	
		
});

function mostra(val) {
	clearTimeout(timemenu);
	if(val != nulla) {
		$j('#'+val).parents('ul').show("fast");
	} else {
		$elemento.show("fast");
	}

	timemenu = setTimeout("nascondi()", 3000 );
}

function nascondi() {
	clearTimeout(timemenu);
	$elemento.hide("fast");
	aperto = '';
}

function nasconditutto() {
	$j("#nav li").each(function() {
		$j("ul",this).hide('slow');
	});
	aperto = '';
}

