﻿var Cardec = {
	GlobalMenu : {
		showTimeout : -1,
		hideTimeout : -1,

		Show : function(menuSuffix) {
			Cardec.GlobalMenu.hideAll();
			if (Cardec.GlobalMenu.hideTimeout >= 0)
				window.clearTimeout(Cardec.GlobalMenu.hideTimeout);
			if (Cardec.GlobalMenu.showTimeout >= 0)
				window.clearTimeout(Cardec.GlobalMenu.showTimeout);
			var tMenu = document.getElementById('menu' + menuSuffix);
			var tSubMenu = document.getElementById('submenu' + menuSuffix);
			if (tMenu && tSubMenu) {
				Creative.Waad.Css.AddClassToElement(tMenu, 'hover');
				tSubMenu.style.display = 'block';
			}
		},	
	
		ShowDelayed : function(menuSuffix) {
			if (Cardec.GlobalMenu.showTimeout >= 0)
				window.clearTimeout(Cardec.GlobalMenu.showTimeout);
			var tFunctionCall = 'Cardec.GlobalMenu.Show(\'' + menuSuffix + '\')';
			Cardec.GlobalMenu.showTimeout = window.setTimeout(tFunctionCall, 60);
		},
	
		Hide : function(menuSuffix) {
			var tMenu = document.getElementById('menu' + menuSuffix);
			var tSubMenu = document.getElementById('submenu' + menuSuffix);
			if (tMenu && tSubMenu) {
				Creative.Waad.Css.RemoveClassFromElement(tMenu, 'hover');
				tSubMenu.style.display = 'none';
			}
		},
		
		HideDelayed : function(menuSuffix) {
			if (Cardec.GlobalMenu.hideTimeout >= 0)
				window.clearTimeout(Cardec.GlobalMenu.hideTimeout);
			if (Cardec.GlobalMenu.showTimeout >= 0)
				window.clearTimeout(Cardec.GlobalMenu.showTimeout);
			var tFunctionCall = 'Cardec.GlobalMenu.Hide(\'' + menuSuffix + '\')';
			Cardec.GlobalMenu.hideTimeout = window.setTimeout(tFunctionCall, 250);
		},
	
		hideAll : function() {
			var tGlobalMenu = document.getElementById('global_navigation');
			if (tGlobalMenu) {
				for (var i=0; i < tGlobalMenu.childNodes.length; i++) {
					var tNode = tGlobalMenu.childNodes[i];
					if (tNode.nodeName.toUpperCase() == 'DIV' && Creative.Waad.Css.ElementHasClass(tNode, 'global_navigation_menu'))
						Cardec.GlobalMenu.Hide(tNode.id.substr(4));
				}
			}
		}	
	}
}
