/**************************************************************************************/
/*							Javascript menu functions								  */
/*								Joost Breed											  */
/*							     13-1-2002											  */
/**************************************************************************************/

var currentClassName;
var currentSubClassName;
var menuHideTimer = null;
var menuShowTimer = null;
var MenuShown = null;

var MENU_SHADOW_COLOR = '#666666';
var MENU_SHADOW_WIDTH = 3;
var menuShowDelay = 400;
var menuHideDelay = 300;

var global = window.document
global.fo_shadows = new Array;


function MenuAction(action, obj, url)
{	
	switch (action)
	{
		case 'onmouseover':
			//Change appearance of menu item
			currentClassName = obj.className;
			obj.className = 'clsMenuTextMouseOver'
	
			//If the menu which is to get shown is already shown then cancel hide event.
			if (MenuShown == "sm" + obj.id)
			{
				clearTimeout(menuHideTimer);
				menuHideTimer = null;
			}	
			
			//If there is already a 'show' timer enabled, then clear it
			if (menuShowTimer) 
			{
				clearTimeout(menuShowTimer);
				menuShowTimer = null;
			}
			
			//Open a submenu, with a delay
			menuShowTimer = window.setTimeout("ShowSubMenu('sm" + obj.id + "','" + obj.id + "')", menuShowDelay);
			break;
		case 'onmouseout':
			//Change appearance of menu item
			obj.className = currentClassName;
			
			//Hide the div, with a delay
			menuHideTimer = window.setTimeout("HideSubMenu('sm" + obj.id + "')", menuHideDelay);
			break;
		case 'onmouseclick':
			if (url == '') return;
			document.location.href = url;
			break;
	}
}



function ShowSubMenu(DivID, ParentID)
{	
	if (MenuShown == DivID) return;
	MenuShown = DivID;
	
	//Position div
	document.all(DivID).style.position = 'absolute';
	document.all(DivID).style.left = document.all('tableMain').offsetLeft + document.all('tableLeftFrame').offsetLeft + document.all('tableMenuMain').offsetLeft + document.all('tableMenu1').offsetWidth - 5;
	document.all(DivID).style.top = document.all('tableTitleBar').offsetHeight + ((document.all('tableMenu' + ParentID).offsetHeight + 1) * parseInt(ParentID)) - 27;
	
	//Make shadow
	MakeShadow(document.all(DivID), MENU_SHADOW_COLOR, MENU_SHADOW_WIDTH);
	
	//Make div visible
	document.all(DivID).style.display = '';
	document.all(DivID).focus();
}


function HideSubMenu(DivName)
{
	//Hide the div
	if (MenuShown == DivName) MenuShown = null;
	if (document.all[DivName].tagName != "DIV") return;
	document.all[DivName].style.display='none'
	var i
	for (i=0; i<global.fo_shadows.length; i++)
	{	
		global.fo_shadows[i].removeNode(true);
	}
	global.fo_shadows = new Array();
}




/*function TDMenuAction(action, obj)
{	
	if (menuHideTimer) 
	{	
		clearTimeout(menuHideTimer);
		menuHideTimer = null;
	}
			
	switch (action)
	{
		case 'onmouseover':
			//Change appearance of menu item
			currentSubClassName = obj.className;
			obj.className = 'clsMenuTextMouseOver'
			break;
		case 'onmouseout':
			//Change appearance of menu item
			obj.className = 'clsMenuTextNormal';
			break;
		case 'onmouseclick':
			//navigate away
			if (url == '') return
			document.location.href = url;
			break;
	}
}*/


function SubMenuAction(action, obj, url)
{	
	switch (action)
	{
		case 'onmouseover':
			//Change appearance of menu item
			
			if (obj.tagName == "TD")
			{
				currentSubClassName = obj.className;
				obj.className = 'clsMenuTextMouseOver'
			}
			
			if (menuHideTimer) 
			{	
				clearTimeout(menuHideTimer);
				menuHideTimer = null;
			}
			break;
		case 'onmouseout':
			//Change appearance of menu item
			if (obj.tagName == "TD") obj.className = 'clsMenuTextNormal';
			menuHideTimer = window.setTimeout("HideSubMenu('" + obj.id +"')", menuHideDelay);
			break;
		case 'onmouseclick':
			//navigate away
			if (url == '') return
			document.location.href = url;
			break;
	}
}


//Creates a shadow around an element
function MakeShadow(el, color, size)
{
	var i;
	for (i=size; i>0; i--)
	{	
		var rect = document.createElement('div');
		var rs = rect.style
		rs.position = 'absolute';
		rs.left = (el.style.posLeft + i) + 'px';
		rs.top = (el.style.posTop + i) + 'px';
		rs.width = el.style.posWidth;
		rs.height = el.style.height;
		rs.zIndex = el.style.zIndex - i;
		rs.backgroundColor = color;
		var opacity = 1 - i / (i + 1);
		rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
		el.insertAdjacentElement('afterEnd', rect);
		rect.style.display='';
		global.fo_shadows[global.fo_shadows.length] = rect;
	}
}

function HideSubMenus(MenuShown)
{
	
	
	if (menuShowTimer) 
	{	
		clearTimeout(menuShowTimer);
		menuShowTimer = null;
	}
		
	HideSubMenu(MenuShown);
	MenuShown = null;
}
