var menuVoci;
$(function() {
	menuVoci = (function() {
		var $menu = $("ul.menu");
		var submenu = $("ul.submenu", $menu);
		var isopen = false;
		var submenu_open = null;

		$("a.esterno", $menu).attr({"target": "_new"});
		var me = {
			show: function() {
				isopen = true;
				if (ie6)
					$menu.show();
				else
					$menu.slideDown(800);
			},
			hide: function() {
				isopen = false;
				if (ie6)
					$menu.hide();
				else
					$menu.slideUp(800);
			}
		};
		
		$("div.titolo_menu").click(function() {
			if (!isopen) {
				me.show();
			} else {
				me.hide();
			}
		});
		
		$(">li>a", $menu)
			.css({color: "rgb(98,98,98)"});

		$("li>a", $menu)
			.hover(
				function(){
					if ($(this).parent().parent().hasClass("submenu"))
						$(this).stop(false,true).animate({color: "rgb(98,98,98)"}, 120);
					else if (layoutChiaro)
						$(this).stop(false,true).animate({color: "rgb(0,0,0)"}, 120);
					else
						$(this).stop(false,true).animate({color: "rgb(255,255,255)"}, 120);
				},
				function(){
					if (!$(this).parent().parent().hasClass("submenu"))
						$(this).stop(false,true).animate({color: "rgb(98,98,98)"}, 120);
					else if (layoutChiaro)
						$(this).stop(false,true).animate({color: "rgb(0,0,0)"}, 120);
					else
						$(this).stop(false,true).animate({color: "rgb(255,255,255)"}, 120);
				}
			);

		$("a", $menu).click(function(e) {
			if (($(this).attr("href") !== undefined)&&($(this).attr("href") != "")) /* IE7 lascia href a stringa vuota */
				return true;

			var s = $("ul.submenu", $(this).parent());
			if (submenu_open !== null) {
				submenu_open.slideUp(200);
				if (s.attr("class") === submenu_open.attr("class")) {
					submenu_open = null;
					return;
				}
			}
			if (!s.length)
				return;
			submenu_open = s;
			submenu_open.slideDown(200);

			return false;
		});
		
		me.hide();
		submenu.hide();

		return me;		
	})();
});