/**
 * This file contains standard functions used throughout the application.
 * The function defined in this file are used for dropdown menu items.
 *
 * @author Herman Bredewoud
 * @version 1.00
 * @name Dropdown menu Script
 */
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variable used to check if a menu is active.
var m_bMenuDropActive		= false;

// Variable containing the last active menu item.
var m_aMenuDropActive		= Array();

// Variable to set the level of menu collapsings.
var m_iMenuDropLevel		= 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function MENU_DROPDOWN_search(a_oEvent) {
	// Boolean to stop the parent walkover loop.
	var bObjectFound = false;
	
//	// Target object.
	var oHTML = OBJ_getTarget(a_oEvent);
	var oParent = oHTML;

	for (var i=0; i<5; i++) {
		iCounter = i;
		//alert(OBJ_getAttribute(oHTML, 'class'));
		switch (OBJ_getAttribute(oHTML, 'class')) {
			case "submenuItem":
//				oHTML.onMouseOut = 'MENU_DROPDOWN_disable();';
				MENU_DROPDOWN_disable();
				bObjectFound = true;
				break;
			case "submenuItemActive":
//				oHTML.onMouseOut = 'MENU_DROPDOWN_disable();';
				MENU_DROPDOWN_disable();
				bObjectFound = true;
				break;
			case "menuChildItem menuDropdownLinkSub":
				bObjectFound = true;
				break;
			case "menuChildItemActive menuDropdownLinkSub":
				bObjectFound = true;
				break;
			case "menuChildItem":	
				bObjectFound = true;
				break;
			case "menuChildItemActive":	
				bObjectFound = true;
				break;
			default:
				oHTML = oParent.parentNode;
				break;
		}
		
		if (bObjectFound) {
			MENU_DROPDOWN_showSubMenu(oHTML);
			break;
		}
	}
	
	if (!bObjectFound) {
		MENU_DROPDOWN_disable();
	}
	
	//if (!bObjectFound && iCounter==4) {
//		if (MENU_DROPDOWN_getActiveObject()) {
//			MENU_DROPDOWN_showSubMenu(MENU_DROPDOWN_getActiveObject());
//		}
//	}
}

function MENU_DROPDOWN_disable() {
	if (m_bMenuDropActive) {
		oTempAll = m_aMenuDropActive.pop();
		if (oTempAll){
			OBJ_setStyle(oTempAll,'display','none');
			MENU_DROPDOWN_disable();
		}else {
			m_bMenuDropActive = false;
		}
	}
}

function MENU_DROPDOWN_showSubMenu(a_oTarget) {
	if (oObj = document.getElementById(OBJ_getAttribute(a_oTarget, 'target'))) {
			m_bMenuDropActive = true;
			
			aDimensions = OBJ_sizePositions(a_oTarget);
			
			if(OBJ_getAttribute(a_oTarget, 'class') == 'menuDropdownLinkSub') {
				OBJ_setStyle(oObj,'left',(aDimensions['x']+aDimensions['w'])+"px");
				OBJ_setStyle(oObj,'top',(aDimensions['y']+"px"));
			} else {
				OBJ_setStyle(oObj,'left',(aDimensions['x']+"px"));
				OBJ_setStyle(oObj,'top',(aDimensions['y']+aDimensions['h'])+"px");
			}
			
			OBJ_setStyle(oObj,'display','block');
			MENU_DROPDOWN_setActiveObject(oObj, a_oTarget);
	} else {
		if (OBJ_getAttribute(MENU_DROPDOWN_getActiveObject(),'id') != OBJ_getAttribute(OBJ_getParent(a_oTarget),'id')) {
			OBJ_setStyle(MENU_DROPDOWN_getActiveObject(),'display','none');
		}
	}
}

function MENU_DROPDOWN_setActiveObject(a_oObj, a_oTarget) {
	if (m_aMenuDropActive.length == 0) {
		m_aMenuDropActive.push(a_oObj);
	} else {
		oTemp = MENU_DROPDOWN_getActiveObject();
		
		if (oTemp.id != a_oObj.id) {
			if(OBJ_getAttribute(a_oTarget, 'class') == 'menuDropdownLinkMain') {
				OBJ_setStyle(oTemp,'display','none');
				MENU_DROPDOWN_disable();

				m_aMenuDropActive.push(a_oObj);
			} else {
				
				if (OBJ_getParent(a_oTarget).className == "menuDropdownContainerSub" && oTemp.id != OBJ_getParent(a_oTarget).id) {
					OBJ_setStyle(oTemp,'display','none');
				}
				
				m_aMenuDropActive.push(a_oObj);
			}
		} 
	}
}

function MENU_DROPDOWN_getActiveObject() {
	if (m_aMenuDropActive.length > 0) {
		oTemp = m_aMenuDropActive[m_aMenuDropActive.length-1];
		return oTemp;
	}
	
	return false;
}

function MENU_DROPDOWN_setInactive() {
	OBJ_setStyle(MENU_DROPDOWN_getActiveObject(),'display','none');
}

