// ************************************************************
//	File Name: 	/js/modifyBGClass.js
//	Author:		Trinity Consulting Group - Robert Joseph
//			rpjoseph@comcast.net
//	Create Date:	03/01/2004
//	Purpose:	Popularity boxes may change location based on user input. 
//			Background color of a popularity box container is dependent on location
//			For this reason the font color of the popularity box elements must change dynamically.
//			This script uses standard DOM Level 1 to traverse the content of the SHTML document.
//			It finds any element (div, td, table, p, etc) that has an id = 'pop_*' where * = any number 
//			currently between 1-4. The script finds the items on the left side by searching
//			the 'location' attribute of the popularity box container.  
//			Once left items are found the script ensures that the className is set to 
//			"*_left" for those items.
//	Platforms Tested: 
//			IE 5.0+ on MS XP, Win2K
//			Netscape 7.1 on MS XP, Win2K
//			IE 5.1 on Macintosh OS 10
//			Netscape 7.1 on Macintosh OS 10
// ************************************************************
// 	The traverseNodes function is a recursive function that navigates to the lowest level 
//	of the DOM Tree until it finds a class containing the text 'light' in any of the 
//	container elements with a location containing 'left'.  It is called by the findItem function.
function traverseNodes(myNode, location)
{
	if(myNode.hasChildNodes)
	{
		newNode = myNode.childNodes
		for(a=0; a<newNode.length; a++)
		{
			if(newNode[a].nodeName != "BR")
			{
				var newNodeClass = newNode[a].className
				if (newNodeClass != null)
				{
					if(newNodeClass.indexOf("dark") >= 0)
					{
						if(location.indexOf("left") >= 0)
						{                   
							var sClassName = newNode[a].className
							newSClassName = sClassName.substring(0, sClassName.indexOf("_")) + "_light"
							newNode[a].className = newSClassName								
						}
					}
					else
					{
						if(newNode[a].hasChildNodes)
						{
							traverseNodes(newNode[a], location)
						}
					}
				}
			}
		}
	}
}
// The findItem function is intended to be called from the onLoad event of the BODY tag element.
// 	It instantiates the DOM and retrieves the container objects to pass to the traverseNodes()
// 	function.
function findItem()
{
	var numberOfPopBoxes = 4
	for(i=0; i<numberOfPopBoxes; i++)
	{
		var curBoxNum = i + 1
		curBoxNum += ''
		var a = "pop_" + curBoxNum
		curNode = document.getElementById(a)
		var vNodeLoc = curNode.getAttribute("location")
        traverseNodes(curNode, vNodeLoc)
	}
}
