// ****************  MENU *******************
var activeSubMenu = false;
var timeOut = 1000;

$(document).ready(function(){
	$(".menu li.main-menu").hover(
		function(){
			subMenu($(this), 1);
		},
		function(){
			
			subMenu($(this), 0);
		}
	);
	$(".left_menu li").hover(
		function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		}
	);

	$(".register").hover(
		function(){
			iconsMenu($('.menu_icons'), 1);
			//$('.menu_icons').show();
		},
		function(){
			iconsMenu($('.menu_icons'), 0);
			//$('.menu_icons').hide();
		}
	);
	$('.menu_icons').hover(
        	function(){
           		overIconsMenu($(this));
        	},
        	function(){
            		iconsMenu($('.menu_icons'), 0);
        	}
    	);
});


function subMenu(obj,show){
	activeSubMenu = t = $('ul', obj);	
	
	if (show){
		$('.menu ul ul').hide();
		$(".menu li.main-menu").removeClass('hover');
		$(obj).addClass('hover');
		t.show();
	}
	else{
		activeSubMenu = false;
	 	setTimeout(function(){hideSubmenu(t)}, timeOut);
	}
}
function hideSubmenu(t){
	if (!activeSubMenu || activeSubMenu != t){
		t.hide();
		$(".menu li.main-menu").removeClass('hover');
		t.parents('li').removeClass('hover');
	}
}
function overMenu(t){
	activeSubMenu = t;
}


function iconsMenu(obj,show){
	activeIconsMenu = t = obj;	
	
	if (show){
		$(".register").addClass('hover');
		t.show();
	}
	else{
		activeIconsMenu = false;
	 	setTimeout(function(){hideIconsmenu(t)}, timeOut);
	}
}
function hideIconsmenu(t){
	if (!activeIconsMenu){
		t.hide();
		$(".register").removeClass('hover');
	}
}
function overIconsMenu(t){
	activeIconsMenu = t;
}

