var HOT_COLOR = "#D5AE65";
var COLD_COLOR = "white";
var currentSubNavShowing = "";
var currentSubNavLinkShowing = "";

/***********************
* showSubNav - show a subnav section of the tree
* baseID - the base class name for the section
		   mainNav[baseID] &  subNav[baseID]
*************************/
function showSubNav( baseID, shouldLightUpRoot )
{
	
	
	var mainNav = document.getElementById( "mainNav" + baseID )
	var subNav = document.getElementById( "subNav" + baseID )
		if (subNav) {
			var oldSubNavStyle = subNav.style.display
		} else {
			subNav = null
	}
	
	closeAllSubNav();
	
	//default light up root to true
	shouldLightUpRoot = ( shouldLightUpRoot != null) ? shouldLightUpRoot : true;
	
	
	if( mainNav != null && subNav != null )
	{
		subNav.style.display = ( oldSubNavStyle == "block" ) ? "none" : "block";
		if( shouldLightUpRoot )
		{
			mainNav.style.color = ( oldSubNavStyle == "block" ) ? COLD_COLOR : HOT_COLOR;
		}
		
		//save which section is open
		currentSubNavShowing = baseID;
	}
	
}	

/***********************
* lightupNav - lights up a nav section that does not have any sub links
*************************/
function lightupNav( baseID )
{
	var mainNav = document.getElementById( "mainNav" + baseID )
	
	if( mainNav != null )
	{
		mainNav.style.color = HOT_COLOR;
	}
}

/***********************
* unlightupNav - lights up a nav section that does not have any sub links
*************************/
function unlightupNav( baseID )
{
	var mainNav = document.getElementById( "mainNav" + baseID )
	if( mainNav != null )
	{
		mainNav.style.color = COLD_COLOR;
	}
}


/***********************
* hideNav - hides a section of the tree
*************************/
function hideNav( baseID )
{
	
	var mainNav = document.getElementById( "mainNav" + baseID );
	var subNav = document.getElementById( "subNav" + baseID );
	
	//hide the section and set the root link to cold color
	if( mainNav != null && subNav != null )
	{
		subNav.style.display =  "none";
		mainNav.style.color = COLD_COLOR;
	}
	
	//if current section unhight the current section link.
	if(currentSubNavShowing == baseID)
	{
		var subNavLink = document.getElementById( currentSubNavLinkShowing );
		
		if( subNavLink != null )
		{
			subNavLink.style.color = COLD_COLOR;
		}
	}
}

/***********************
* setCurrentSubNavLink
*************************/
function setCurrentSubNavLink( sectionBaseId, subLinkID)
{
	
	//open the menu
	showSubNav( sectionBaseId, false )
	
	//highlight the section
	var subLink = document.getElementById( subLinkID );
	if( subLink != null )
	{
		subLink.style.color = HOT_COLOR;
	}
	
	currentSubNavLinkShowing = subLinkID;
}

/***********************
* closeAllSubNav - close all open sub treess
*************************/
function closeAllSubNav()
{

	//currentSection & SECTION_FOO in bb.js
	if( currentSection ==  SECTION_MEN )
	{
		hideNav('203');
		hideNav('210');
		hideNav('223');
		hideNav('218');
		hideNav('522');
		hideNav('226');
		hideNav('228');
		hideNav('227');
		hideNav('330');
		hideNav('305');
		unlightupNav('NewArrivals');
		unlightupNav('ShopByOutfit');
		unlightupNav('224');
		unlightupNav('217');
		unlightupNav('222');
		unlightupNav('225');
		unlightupNav('227');
		return;
	}
	
	if( currentSection ==  SECTION_WOMEN )
	{
		hideNav('242');
		hideNav('238');
		hideNav('241');
		hideNav('248');
		hideNav('314');
		unlightupNav('NewArrivals');
		unlightupNav('ShopByOutfit');
		unlightupNav('245');
		unlightupNav('239');
		unlightupNav('237');
		unlightupNav('374');
		unlightupNav('246');
		unlightupNav('378');
		return;
	}
	
	if( currentSection ==  SECTION_BOYS )	
	{
		hideNav('352');
		hideNav('396');
		hideNav('405');
		hideNav('353');
		hideNav('355');
		unlightupNav('NewArrivals');
		unlightupNav('ShopByOutfit');
		unlightupNav('356');
		return;
	}
	
	if( currentSection ==  SECTION_BROOKSBUYS )
	{
		hideNav('Men');
		hideNav('Women');
		hideNav('Boys');
		return;
	}
	
	if( currentSection ==  SECTION_GIFTCARD )
	{
		return;
	}
	
	if( currentSection ==  SECTION_HELP )
	{
		hideNav('CustomerService');
		hideNav('Privacy');
		hideNav('GiftServices');
		hideNav('CompanyInfo');
		hideNav('PlacingOrders');
		hideNav('Website');
		hideNav('Shopping');
		hideNav('Delivery');
		hideNav('AppropriateDressing');
		hideNav('BrooksCard');
		hideNav('Registration');
		hideNav('ContactUs');
		return;
	}
	
}