﻿//styles we care about
var kstrStyleTopNavSelected = "topnavselected"
var kstrStyleTopNavUnselected = "topnav"
var kstrStyleHomeNavSelected = "homenavselected"
var kstrStyleHomeNavUnselected = "homenavunselected"
var kstrStyleHomeNavSelectedHighlight = "homenavselectedhighlight"
var kstrStyleHomeNavUnselectedHighlight = "homenavunselectedhighlight"
var kstrStyleLeftNavSelected = "leftnavselected"
var kstrStyleLeftNavUnselected = "leftnavunselected"
var kstrStyleLeftNavSubSelected = "leftnavsubselected"
var kstrStyleLeftNavSubUnselected = "leftnavsubunselected"

//the top menu names
var kstrMenuHome = "menuHome"
var kstrMenuApproach = "menuApproach"
var kstrMenuServices = "menuServices"
var kstrMenuCareers = "menuCareers"
var kstrMenuAboutUs = "menuAboutUs"
var kstrMenuContactUs = "menuContactUs"

var kstrNodeTopAvailable = "nodeTopAvailable"
var kstrNodeTopCaseStudies = "nodeTopCaseStudies"
var kstrNodeTopDevelopment = "nodeTopDevelopment"
var kstrNodeTopForDevelopers = "nodeTopForDevelopers"
var kstrNodeTopForExecutives = "nodeTopForExecutives"
var kstrNodeTopForInfrastructure = "nodeTopForInfrastructure"
var kstrNodeTopForProductSupport = "nodeTopForProductSupport"
var kstrNodeTopFunctional = "nodeTopFunctional"
var kstrNodeTopInfrastructure = "nodeTopInfrastructure"
var kstrNodeTopOverview = "nodeTopOverview"
var kstrNodeTopOurPeople = "nodeTopOurPeople"
var kstrNodeTopOurDifference = "nodeTopOurDifference"
var kstrNodeTopSupport = "nodeTopSupport"
var kstrNodeTopSustainable = "nodeTopSustainable"
var kstrNodeTopUsable = "nodeTopUsable"
var kstrNodeSubJayCincotta = "nodeSubJayCincotta"
var kstrNodeSubKendallMiller = "nodeSubKendallMiller"

//Our current menu and left nav items so we can track what is current
var curTopMenuName = "";
var curLeftNodeName = "";
var curLeftSubNodeName = "";

//set the current menu name, storing the variable and updating the style of the correct menu cell
function SetCurrentMenu(menuName)
{
	//if there is a current top menu item, we need to set its style the other way
	if (curTopMenuName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curTopMenuName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleTopNavUnselected);
	    }
	}
	
	//now set the new top menu item and update its style
	curTopMenuName = menuName;
	
	if (curTopMenuName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curTopMenuName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleTopNavSelected);
	    }
	}
}

//set the current node name, storing the variable and updating the style of the correct menu cell
function SetCurrentNode(topNodeName, subNodeName)
{
	//if there is a current top menu item, we need to set its style the other way
	if (curLeftNodeName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curLeftNodeName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleLeftNavUnselected);
	    }
	}
	
	if (curLeftSubNodeName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curLeftSubNodeName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleLeftNavSubUnselected);
	    }
	}
	
	
	//now set the new node name(s) so we cna update their styles
	curLeftNodeName = topNodeName;
	curLeftSubNodeName = subNodeName;
	
	if (curLeftNodeName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curLeftNodeName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleLeftNavSelected);
	    }
	}
	
	if (curLeftSubNodeName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curLeftSubNodeName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleLeftNavSubSelected);
	    }
	}
}

//set the current node name, storing the variable and updating the style of the correct menu cell
function SetCurrentHomeNode(topNodeName, subNodeName)
{
	//if there is a current top menu item, we need to set its style the other way
	if (curLeftNodeName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curLeftNodeName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleHomeNavUnselected);
	    }
	}
	
	if (curLeftSubNodeName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curLeftSubNodeName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleHomeNavSubUnselected);
	    }
	}
	
	
	//now set the new node name(s) so we cna update their styles
	curLeftNodeName = topNodeName;
	curLeftSubNodeName = subNodeName;
	
	if (curLeftNodeName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curLeftNodeName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleHomeNavSelected);
	    }
	}
	
	if (curLeftSubNodeName.length > 0 )
	{
	    var curMenuElement = document.getElementById(curLeftSubNodeName);
	    if (curMenuElement != null)
	    {
	    	SetElementStyleWithChildren(curMenuElement, kstrStyleHomeNavSubSelected);
	    }
	}
}



//Get the correct unhovered style for the current top menu item, which is different if we're the current menu
function GetNavMenuClass(menuName)
{
	var correctStyleName = "";

	//if the specified menu is current
	if (curTopMenuName == menuName)
	{
		correctStyleName = kstrStyleTopNavSelected;
	} else {
		correctStyleName = kstrStyleTopNavUnselected;
	}
	
	return correctStyleName;
}


//Get the correct unhovered style for the current left menu item, which is different if we're the current menu
function GetHomeNavNodeClass(nodeName)
{
	var correctStyleName = "";

	//if the specified menu is current
	if (curLeftNodeName == nodeName)
	{
		correctStyleName = kstrStyleHomeNavSelected;
	} else {
		correctStyleName = kstrStyleHomeNavUnselected;
	}
	
	return correctStyleName;
}


//Get the correct unhovered style for the current left menu item, which is different if we're the current menu
function GetHomeNavNodeHighlightClass(nodeName)
{
	var correctStyleName = "";

	//if the specified menu is current
	if (curLeftNodeName == nodeName)
	{
		correctStyleName = kstrStyleHomeNavSelectedHighlight;
	} else {
		correctStyleName = kstrStyleHomeNavUnselectedHighlight;
	}
	
	return correctStyleName;
}


//Get the correct unhovered style for the current left menu item, which is different if we're the current menu
function GetLeftNavNodeClass(nodeName)
{
	var correctStyleName = "";

	//if the specified menu is current
	if (curLeftNodeName == nodeName)
	{
		correctStyleName = kstrStyleLeftNavSelected;
	} else {
		correctStyleName = kstrStyleLeftNavUnselected;
	}
	
	return correctStyleName;
}

//Get the correct unhovered style for the current left menu item, which is different if we're the current menu
function GetLeftNavSubNodeClass(nodeName)
{
	var correctStyleName = "";

	//if the specified menu is current
	if (curLeftSubNodeName == nodeName)
	{
		correctStyleName = kstrStyleLeftNavSubSelected;
	} else {
		correctStyleName = kstrStyleLeftNavSubUnselected;
	}
	
	return correctStyleName;
}

function SetElementStyleWithChildren(tableElement, newStyleName)
{
	//we need to set the style of the current table cell and any A element within it
	tableElement.className = newStyleName;
	
	//now see if we have an A record underneith it
	var curChildElement = null;
	var curChildElementIndex = null;
	for (curChildElementIndex = 0; curChildElementIndex < tableElement.childNodes.length; curChildElementIndex++) 
	{
		curChildElement = tableElement.childNodes[curChildElementIndex];
		
		//now careful - because we're using child nodes, we could get back text and html elements, and we only care about HTML ones
		if (( curChildElement.nodeType == 1) && ( curChildElement.tagName == "A" ))
		{
			//set the style
			curChildElement.className = newStyleName;
		}
	}
}
