/////////////////////////////////////////////////////////////////////////////
// Function : gl_topnavigation
// Comments : 
/////////////////////////////////////////////////////////////////////////////

function gl_topnavigation(strShowHome, strStartLevel, strNumLevels, strRelativeRoot)
{
	this.m_ShowHome   = false;
	
	this.m_StartLevel = 1;
	this.m_NumLevels  = 1;
	this.m_EndLevel   = 1;
	
	this.m_NavPath    = g_navNode_Path;
			
	gl_topnavigation.prototype.Display = gl_topnavigation_Display;
	gl_topnavigation.prototype.DisplaySubLevel = gl_topnavigation_DisplaySubLevel;
		
	if (strShowHome == 'true')
		this.m_ShowHome = true;
		
	if (strStartLevel != '')
	{
		var value = parseInt(strStartLevel);
		if (value != NaN)
			this.m_StartLevel = value;
	}
	
	if (strNumLevels != '')
	{
		var value = parseInt(strNumLevels);
		if (value != NaN)
			this.m_NumLevels = value;
	}

	this.m_EndLevel = this.m_StartLevel + this.m_NumLevels - 1 ;
}

function gl_topnavigation_Display (node)
{
	document.write('<table class=subTab-off cellspacing=0 cellpadding=0 border=0><tbody><tr>');
	this.DisplaySubLevel(node);	
	document.write('</tr></tbody></table>');
}

function gl_topnavigation_DisplaySubLevel (node)	
{
	var bSelected = false;
	var bDisplay  = false;

	var nodeLevel = node.m_level+1;
	
	if (nodeLevel > 6)
		nodeLevel = 6;
		
	var ds = new Array();
	var di = 0;
	var count = 0;

	var selectedNode = null;

	if (this.m_ShowHome && (node.m_level == 0))
		count = -1;

	var href = '';
	var label = '';
	
	if (node.m_level >= this.m_StartLevel-1 && node.m_level < this.m_EndLevel)
		bDisplay = true;

	for ( ; count < node.m_subNodes.length; count++)
	{
		bSelected = false;

		if (count == -1)	// Root/home link 
		{	
			// this is only really applicable if we're working the top level
			// but the same technique could be used to display a generalised "back-up-one-level")
			
			if ( (this.m_NavPath.length == node.m_level+1) &&
				 (this.m_NavPath[node.m_level] == node.m_id) )
			{
				bSelected = true;
			}
			
			label = node.m_label;
			href  = node.m_href;
		}
		else
		{	
			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)
				{
					<!--$if ssGetNodeProperty(nodeId, "ShowInTopNav")-->
					bSelected = true;
					selectedNode = node.m_subNodes[count];
					<!--else-->
				}
			}
			label = node.m_subNodes[count].m_label;
			href = node.m_subNodes[count].m_href;
		}

		if (bSelected)
		{
			nodeClass = 'subTab-on';
		}
		else
		{
			nodeClass = 'subTab-off';
		}

		if (bDisplay)
		{
			ds[di++] = '<td><table class="' + nodeClass + '" height=21 cellspacing=0 cellpadding=0 border=0><tbody><tr><td></td><td><img height=1 border=0 alt="" src="/stellent/fragments/gl_topnavigation/spacer.gif" width=139></td><td></td></tr><tr><td><img alt="" border=0  src="/stellent/fragments/gl_topnavigation/spacer.gif" width=1></td><td align=middle height=20><a';

			ds[di++] = ' class="' + nodeClass + '" href="'+ href + '">';
			
			ds[di++] = label ;
			ds[di++] = '</a></td><td bgcolor="ffffff"><img alt="" border=0 src="/stellent/fragments/gl_topnavigation/spacer.gif" width=1></td></tr></tbody></table></td>';


		}
	} 
	
	if (bDisplay)
	{
		document.write(ds.join(''));
	}

	
	if (selectedNode != null)
		this.DisplaySubLevel (selectedNode);
}


