/* (c) 2008 Mark Tomsu */

var menu_timers = new Array();
var main_menu_tab = false;
var main_menu_keepalive = '';
var sub_menu_keepalive = '';
var menu_hide_delay = 700; // milliseconds
var dont_hide = '';

// hide all, fix png width issue
function init() {
	if (menu_names.length > 0)
		for (i = 0; i < menu_names.length; i++) {
			coords = dojo.coords('div-' + menu_names[i]);
			// fix png shadow width, ie can't handle it
			document.images[menu_names[i] + '-fix'].width = coords.w - 15;
			dojo.style('menu-' + menu_names[i], 'display', 'none');
			var foob = true;
		}
}

// kill timer, position it, show it
function showMainMenu(n, tab) {
	// hide other main menus
	for (i = 0; i < main_menu_names.length; i++)
		doMenuOut('menu-' + main_menu_names[i]);
	
	main_menu_keepalive = n;
	main_menu_tab = tab;
	
	menu_name = 'menu-' + n;
	nav_name = 'nav-' + n;
	
	// make sure there is a menu available
	if (dojo.byId(menu_name) == null)
		return;
	
	killTimer(n);
	
	var nav = dojo.byId(nav_name);
	var menu = dojo.byId(menu_name);
	
	x_offset = tab ? 0 : -18;
	
	coords = dojo.coords(nav);
	t = (coords.y + coords.h - 2).toString() + 'px';
	l = (coords.x + x_offset).toString() + 'px';
	menu.style.zIndex = 100;
	
	showMenu(menu, t, l);
}

function showSubMenu(n) {
	sub_menu_keepalive = n;
	
	// hide sub menus
	if (sub_menu_names.length > 0)
		for (i = 0; i < sub_menu_names.length; i++)
			if (dont_hide == '' || dont_hide != sub_menu_names[i])
				dojo.style('menu-' + sub_menu_names[i], 'display', 'none');
	dont_hide = '';
	
	menu_name = 'menu-' + n;
	nav_name = 'nav-' + n;
	
	// make sure there is a menu available
	if (dojo.byId(menu_name) == null)
		return;
	
	killTimer(n);
	
	var nav = dojo.byId(nav_name);
	var menu = dojo.byId(menu_name);
	
	coords = dojo.coords(nav);
	t = (coords.y - 1).toString() + 'px';
	l = (coords.x + coords.w + 2).toString() + 'px';
	menu.style.zIndex = 100;
	
	showMenu(menu, t, l);
}

// display individual product menu
// hide other product menus first
function showProductMenu(n, me) {
	// hide product menus
	if (product_menu_names.length > 0)
		for (i = 0; i < product_menu_names.length; i++)
			dojo.style('menu-' + product_menu_names[i], 'display', 'none');
	
	menu_name = 'menu-' + n;
	nav_name = 'nav-' + main_menu_keepalive + '-' + n;
	
	// make sure there is a menu available
	if (dojo.byId(menu_name) == null)
		return;
	
	killTimer(n);
	
	var nav = dojo.byId(nav_name);
	var menu = dojo.byId(menu_name);
	
	if (typeof(me) != 'undefined')
		nav = me;
	
	coords = dojo.coords(nav);
	t = (coords.y - 2).toString() + 'px';
	l = (coords.x + coords.w + 1).toString() + 'px';
	menu.style.zIndex = 100;
	
	showMenu(menu, t, l);
}

// when rolling over an individual product menu
// keep the solutions or products menu alive
function menuKeepalive(n) {
	dont_hide = n;
	
	showMainMenu(main_menu_keepalive, main_menu_tab);
	if (main_menu_keepalive == 'solutions')
		showSubMenu(sub_menu_keepalive);
	
	killTimer('hide_product_menus');
	killTimer('solutions');
	killTimer(n);
}

// when rolling out of an individual product menu
// also hide the parent menu
function hideKeepalive() {
	hideMenu(main_menu_keepalive);
	if (main_menu_keepalive == 'solutions')
		hideMenu(sub_menu_keepalive);
}

// position and show any menu
function showMenu(menu, t, l) {
	menu.style.top = t;
	menu.style.left = l;
	doMenuIn(menu);
}

// start a timer to hide any menu
function hideMenu(n) {
	// make sure there is a menu available
	if (dojo.byId('menu-' + n) == null)
		return;
	
	menu_timers[n] = setTimeout("doMenuOut('menu-" + n + "')", menu_hide_delay);
}

// set timer to hide any visible individual product menus
// when the mouse leaves the product list
function hideProductMenus() {
	menu_timers['hide_product_menus'] = setTimeout("doHideProductMenus()", menu_hide_delay);
}

// performed after the timer expires
function doHideProductMenus() {
	/*
	if (product_menu_names.length > 0)
		for (i = 0; i < product_menu_names.length; i++)
			hideMenu(product_menu_names[i]);
	*/
	if (product_menu_names.length > 0)
		for (i = 0; i < product_menu_names.length; i++)
			dojo.style('menu-' + product_menu_names[i], 'display', 'none');
}

// kill an active timeout
function killTimer(n) {
	if (typeof(menu_timers[n]) != 'undefined')
		clearTimeout(menu_timers[n]);
}

// apply effects here or just show/hide
// effects have been removed, they run poorly when displayed over Flash content
function doMenuIn(node) {
	/*
	var fade = dojo.fadeIn({
		node: node,
		duration: 100
	});
	var wipe = dojo.fx.wipeIn({
		node: node,
		duration: 150
	});
	var combo = dojo.fx.combine([fade, wipe]);
	combo.play();
	*/
	dojo.style(node, 'display', '');
}

function doMenuOut(node) {
	/*
	var fade = dojo.fadeOut({
		node: node,
		duration: 100
	});
	var wipe = dojo.fx.wipeOut({
		node: node,
		duration: 75
	});
	var combo = dojo.fx.combine([fade, wipe]);
	combo.play();
	*/
	
	dojo.style(node, 'display', 'none');
}