var currentPrimary = 'navInside';
var currentSecondary = 'subInside';
var currentSecondaryElement = '';

/**
 * Opens a submenu on the navigation bar
 * 
 * @param 	primary New primary navigation focused parent
 * @param 	secondary Secondary navigation to open
 * @return 	void
 */
function openSubmenu(primary, secondary) {
	if (currentSecondary != '') {
		document.getElementById(currentSecondary).style.display='none';
	}
	var oldPrimary = document.getElementById(currentPrimary);
	oldPrimary.className = oldPrimary.className.replace(/Active/g,'');
	currentPrimary = primary;
	currentSecondary = secondary;
	var newPrimary = document.getElementById(currentPrimary);
	newPrimary.className = newPrimary.className + " Active";
	document.getElementById(currentSecondary).style.display='inline-block';
}

/**
 * Highlights and sticks the highlighted secondary element
 * 
 * @param	secElem The secondary element being highlighted
 * @return	void
 */
function highlightSecondaryElement(secElem) {
	if (currentSecondaryElement != '') {
		var oldSecElem = document.getElementById(currentSecondaryElement);
		oldSecElem.className = oldSecElem.className.replace(/Active/g,'');
	}
	var newSecElem = document.getElementById(secElem);
	newSecElem.className = newSecElem.className + " Active";
	currentSecondaryElement = secElem;
}

/**
 * Method provided to body onload process to select the navigation sections the user is currently on
 * 
 * @param 	primary New primary navigation focused parent
 * @param 	secondary Secondary navigation to open
 * @param 	secondaryElem Secondary element to highlight
 * @return	void
 */
function selectNavElements(primary, secondary, secondaryElem) {
    // Disable the secondary
    document.getElementById(currentSecondary).style.display='none';
	currentPrimary = primary;
	currentSecondary = secondary;
	currentSecondaryElement = secondaryElem;
	var newPrimary = document.getElementById(currentPrimary);
	newPrimary.className = newPrimary.className + " Active";
	// If the currentSecondaryElement is not empty, then don't select a secondary element
    if (currentSecondaryElement != null && currentSecondaryElement != '') {
	    var newSecElem = document.getElementById(currentSecondaryElement);
	    if (newSecElem != null) {
	    	newSecElem.className = newSecElem.className + " Active";
	    }
    }
	document.getElementById(currentSecondary).style.display='inline-block';
}
