/////////////////////////////////////////////////////////////////////////////
// Function : AquaSureSecondaryNav
// Comments : Builds out the secondary menu displayed on the left-side of the
//            AquaSure website.
/////////////////////////////////////////////////////////////////////////////

function AquaSureSecondaryNav(strTextColor, strHoverColor, strFocusColor, strClassName, 
							strUlStyle, strLiStyle, strAStyle)
{
	this.m_TextColor  = '';
	this.m_HoverColor = '';
	this.m_FocusColor = '';
	this.m_ClassName  = 'AquaSureSecondaryNav';
	
	this.m_ShowHome   = false;
	
	this.m_NavPath    = g_navNode_Path;
	
	this.m_UlStyle = '';
	this.m_LiStyle = '';
	this.m_AStyle = '';
			
	AquaSureSecondaryNav.prototype.Display = AquaSureSecondaryNav_Display;
	AquaSureSecondaryNav.prototype.DisplaySubLevel = AquaSureSecondaryNav_DisplaySubLevel;
		
	if (strTextColor != '')
		this.m_TextColor = strTextColor;
		
	if (strHoverColor != '')
		this.m_HoverColor = strHoverColor;

	if (strFocusColor != '')
		this.m_FocusColor = strFocusColor;

	if (strClassName != '')
		this.m_ClassName = strClassName;
	
	if (strUlStyle != '')
	{
		this.m_UlStyle = strUlStyle;
	}
	
	if (strLiStyle != '')
	{
		this.m_LiStyle = strLiStyle;
	}
	
	if (strAStyle != '')
	{
		this.m_AStyle = strAStyle;
	}
}

function AquaSureSecondaryNav_Display (node)
{
	document.write('<table width="100%" cellspacing="0" cellpadding="0" border="0">');
	this.DisplaySubLevel(node);	
	document.write('</table>');
}

function AquaSureSecondaryNav_DisplaySubLevel (node)	
{
	var bSelected = false;
	var bDisplay  = false;

	var nodeColor = this.m_TextColor;
	var nodeClass = this.m_ClassName
	var nodeLevel = node.m_level+1;
	
	if (nodeLevel > 6)
		nodeLevel = 6;
		
	var ds = new Array();
	var di = 0;
	var count = 0;

	var href = '';
	var label = '';
	
	bDisplay = true;

	if (bDisplay) 
	{
		ds[di++] = '<tr';
		
		if (nodeLevel > 0)
			ds[di++] = ' class="' + nodeClass + '-' + nodeLevel + '"';
		else
			ds[di++] = ' class="' + nodeClass + '"';
		
		//ds[di++] = '><td nowrap>';
		ds[di++] = '><td nowrap><ul style="' + this.m_UlStyle + '">';
//		ds[di++] = '&nbsp;';
	}
	
	var i = 0;
	var nodeFound = false;
	var currentNode = (this.m_NavPath.length >= 2) ? this.m_NavPath[1] : this.m_NavPath[0];
	for (i = 0; i < node.m_subNodes.length; ++i) {
		if (node.m_subNodes[i].m_id == currentNode) {
			// found the sub node for the secondary menu
			node = node.m_subNodes[i];
			nodeFound = true;
			break;
		}
	}
	
	if (!nodeFound)
		return;
		
	for ( ; count < node.m_subNodes.length; count++)
	{
		bSelected = false;
		nodeColor = this.m_TextColor;

		if (this.m_NavPath.length >= node.m_subNodes[count].m_level)
		{
			if (this.m_NavPath[node.m_subNodes[count].m_level] == node.m_subNodes[count].m_id)
			{
				bSelected = true;
				selectedNode = node.m_subNodes[count];
			}
		}
		label = node.m_subNodes[count].m_label;
		href = node.m_subNodes[count].m_href;

		if (bSelected)
		{
			nodeColor = this.m_FocusColor;
			nodeClass = this.m_ClassName + '-focus';
		}
		else
		{
			nodeColor = this.m_TextColor;
			nodeClass = this.m_ClassName;
		}

		if (nodeLevel > 0)
			nodeClass += '-' + nodeLevel;

		if (bDisplay)
		{
			ds[di++] = '<li style="' + this.m_LiStyle + '"><a href="' + href + '"';

			ds[di++] = ' class="' + nodeClass + '"';
			
			if (nodeColor != '')
			{
				ds[di++] = ' style="color:' + nodeColor + '; ' + this.m_AStyle + '"';

				if (!bSelected && this.m_HoverColor != '')
				{
					ds[di++] = ' onmouseover="this.style.color=\'' + this.m_HoverColor + '\'"';
					ds[di++] = ' onmouseout="this.style.color=\'' + nodeColor + '\'"';
				}
			}
			
			ds[di++] = '>';
			ds[di++] = label;
			ds[di++] = '</a></li>';
		}
	} 
	
	if (bDisplay)
	{
		//ds[di++] = '</td></tr>';
		ds[di++] = '</ul></td></tr>';
		document.write(ds.join(''));
	}
}

