/////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2007, 2008, Oracle. All rights reserved.
// Function : NavMultiHorizontal
// Comments : 
/////////////////////////////////////////////////////////////////////////////

function NavMultiHorizontal(strTextColor, strHoverColor, strFocusColor, strSeparator, strClassName, 
							strShowHome, strStartLevel, strNumLevels)
{
	this.m_TextColor  = '';
	this.m_HoverColor = '';
	this.m_FocusColor = '';
	this.m_Separator  = '';
	this.m_ClassName  = 'NavMultiHorizontal';
	
	this.m_ShowHome   = false;
	
	this.m_StartLevel = 1;
	this.m_NumLevels  = 1;
	this.m_EndLevel   = 1;

        this.m_level1Alt = false;
	
	this.m_NavPath    = g_navNode_Path;
			
	NavMultiHorizontal.prototype.Display = NavMultiHorizontal_Display;
	NavMultiHorizontal.prototype.DisplaySubLevel = NavMultiHorizontal_DisplaySubLevel;
		
	if (strTextColor != '')
		this.m_TextColor = strTextColor;
		
	if (strHoverColor != '')
		this.m_HoverColor = strHoverColor;

	if (strFocusColor != '')
		this.m_FocusColor = strFocusColor;

	if (strSeparator != '')
		this.m_Separator = strSeparator;

	if (strClassName != '')
		this.m_ClassName = strClassName;

	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 NavMultiHorizontal_Display (node)
{
    document.write('<div class="menu">');	
    this.DisplaySubLevel(node);	
    document.write('</div>');
}

function NavMultiHorizontal_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 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;

	if (bDisplay) 
	{
		ds[di++] = '<ul id="menu'+nodeLevel+'"';
		
		if (nodeLevel > 0)
			ds[di++] = ' class="' + nodeClass + '-' + nodeLevel + '"';
		else
			ds[di++] = ' class="' + nodeClass + '"';
		
		ds[di++] = '>';
//		ds[di++] = '&nbsp;';
	}	
		
	for ( ; count < node.m_subNodes.length; count++)
	{
		bSelected = false;
		nodeColor = this.m_TextColor;

		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)
				{
					bSelected = true;
					selectedNode = node.m_subNodes[count];
				}
			}
			label = node.m_subNodes[count].cp_AltLabel;
			if(label==null){
			  label = node.m_subNodes[count].m_label;
			}

                        var matches = label.match(/\|/g,label);
                        var numOfLines = 1;
	                if(matches!=null){
			  numOfLines = numOfLines+matches.length;
			}
                        
			var anchorInlineStyle = "";
                        if(numOfLines==1){
			    anchorInlineStyle ="line-height:10px;padding-top:10px;padding-bottom:12px;";
                        } else if(numOfLines==2){
			    anchorInlineStyle ="line-height:10px;padding-top:5px;padding-bottom:7px;";			
			} else if(numOfLines==3){
			    anchorInlineStyle ="line-height:10px;padding-top:0px;padding-bottom:2px;";
			}

                        label = label.replace(/\|/g,"<br>");

			href = node.m_subNodes[count].m_href;
		}

		if (bSelected)
		{
			nodeColor = this.m_FocusColor;
			nodeClass = 'focus';
		}
		else
		{
			nodeColor = this.m_TextColor;
			nodeClass = '';
		}

		//if (nodeLevel > 0)
		//	nodeClass += '-' + nodeLevel;

		if (bDisplay)
		{
			
                        var showAltColor = false;
                        if(node.m_subNodes[count].cp_Menu1AltColor!=null
				&& "TRUE"==node.m_subNodes[count].cp_Menu1AltColor.toUpperCase()){
			  showAltColor = true;		          
                        }
                        if(this.m_level1Alt==false && showAltColor){
                          ds[di++] = '<li style="margin: 0px 0px -5px 0px;padding: 0px;"><img style="margin: 0px;padding: 0px;" src="'+dividerImageURL+'"></li>';			  
                          this.m_level1Alt = true;
                        }
                        

                        if(bSelected){
                          ds[di++] = '<li id="focus'+nodeLevel+'">';
			} else if(showAltColor){
                          ds[di++] = '<li id="alt'+nodeLevel+'">';
                        } else{
                          ds[di++] = '<li>';
                        }

			//change href to the first level 2 node under this node
			if(nodeLevel == 1){
				var parentNode = node.m_subNodes[count];
				var subNode = parentNode.m_subNodes[0];
				if(subNode != null){
					var subNodeHref = subNode.m_href;
					var subNodeLabel = subNode.m_label;
					href = subNodeHref;	
				}
			}
                       
                        ds[di++] = '<a style="'+anchorInlineStyle+'" href="' + href + '"';

			ds[di++] = ' class="' + nodeClass + '"';
			
			if (nodeColor != '')
			{
				ds[di++] = ' style="color:' + nodeColor + ';"';

				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>';

			//if (count < node.m_subNodes.length - 1)
			//{
			//	ds[di++] = '&nbsp;';
			//	ds[di++] = this.m_Separator;
			//	ds[di++] = '&nbsp;';
			//}
			//else
			//{
			//	ds[di++] = '&nbsp;';
			//}
                        ds[di++] = '</li>'
		}
	} 
	
	if (bDisplay)
	{
		ds[di++] = '</ul>';
		document.write(ds.join(''));
	}
	
	if (selectedNode != null)
		this.DisplaySubLevel (selectedNode);
}

