/**
 * 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 MENUDROP_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++) {
		switch (OBJ_getAttribute(oHTML, 'class')) {
			case "menuDropLinkMain":
				bObjectFound = true;
				break;
			case "menuDropLinkSub":
				bObjectFound = true;
				break;
			default:
				oHTML = oParent.parentNode;
				break;
		}
		if (bObjectFound) {
			MENUDROP_showSubMenu(oHTML);
			break;
		}
	}
}

function MENUDROP_disable() {
	if (m_bMenuDropActive) {
		oTempAll = m_aMenuDropActive.pop();
		if (oTempAll){
			OBJ_setStyle(oTempAll,'display','none');
			MENUDROP_disable();
		}else {
			m_bMenuDropActive = false;
		}
	}
}

function MENUDROP_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') == 'menuDropLinkSub') {
				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');
			MENUDROP_setActiveObject(oObj, a_oTarget);
	} else {
		if (OBJ_getAttribute(MENUDROP_getActiveObject(),'id') != OBJ_getAttribute(OBJ_getParent(a_oTarget),'id')) {
			OBJ_setStyle(MENUDROP_getActiveObject(),'display','none');
		}
	}
}

function MENUDROP_setActiveObject(a_oObj, a_oTarget) {
	if (m_aMenuDropActive.length == 0) {
		m_aMenuDropActive.push(a_oObj);
	} else {
		oTemp = MENUDROP_getActiveObject();
		
		if (oTemp.id != a_oObj.id) {
			if(OBJ_getAttribute(a_oTarget, 'class') == 'menuDropLinkMain') {
				OBJ_setStyle(oTemp,'display','none');
				MENUDROP_disable();

				m_aMenuDropActive.push(a_oObj);
			} else {
				
				if (OBJ_getParent(a_oTarget).className == "menuDropContainerSub" && oTemp.id != OBJ_getParent(a_oTarget).id) {
					OBJ_setStyle(oTemp,'display','none');
				}
				
				m_aMenuDropActive.push(a_oObj);
			}
		} 
	}
}

function MENUDROP_getActiveObject() {
	if (m_aMenuDropActive.length > 0) {
		oTemp = m_aMenuDropActive[m_aMenuDropActive.length-1];
		return oTemp;
	}
	
	return false;
}

function MENUDROP_setInactive() {
	OBJ_setStyle(MENUDROP_getActiveObject(),'display','none');
}

