/////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2007, 2008, Oracle. All rights reserved.
// Function : SiteMapPlain
// Comments : 
/////////////////////////////////////////////////////////////////////////////

// this version is heavily parameterised with "mainColor" and "hotColor" 
// just like the navigation fragments
// it might be better to leave it all to stylesheet edits...
// or - better still, leave it as server side stuff to generate the <style> defs 
// and the display code...
var prevLevel = 1;

function SiteMapPlain(strTextColor, strHoverColor, strFocusColor, strClassName, strShowHome, strShowFocus)
{
	this.m_TextColor  = '';
	this.m_HoverColor = '';
	this.m_FocusColor = '';
	this.m_ClassName  = 'SiteMapPlain';
	
	this.m_ShowHome   = false;
	this.m_ShowFocus  = false;	
	
	this.m_NavPath    = g_navNode_Path;
		
	SiteMapPlain.prototype.Display = SiteMapPlain_Display;
	SiteMapPlain.prototype.DisplayNode = SiteMapPlain_DisplayNode;
	
	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 (strShowHome == 'true')
		this.m_ShowHome = true;
		
	if (strShowFocus == 'true')
		this.m_ShowFocus = true;
}

function SiteMapPlain_Display (node)
{
	document.write ('<div class="' + this.m_ClassName + '"');
	
	if (this.m_TextColor != '')
		document.write (' style="color: ' + this.m_TextColor + ';"');
		
	document.write ('>');

	document.write('<table width="100%"><tr><td class="SiteMapPlainColumn">');
	this.DisplayNode(node);
	document.write('</td></tr></table>');
	document.write ('</div>');
}

function SiteMapPlain_DisplayNode(node)	
{
	var nodeColor = this.m_TextColor;
	var nodeClass = this.m_ClassName;
	var nodeLevel = node.m_level;
	
	var levelChange = nodeLevel - prevLevel;
	prevLevel = nodeLevel;
	
	if(levelChange > 0 && nodeLevel > 1){
		document.write('<ul>');
	}
	else if(levelChange < 0 && nodeLevel > 0){
		var i = levelChange;
		while(i < 0){  
			document.write('</ul>');
			i++;
		}
	}
	
	if(node.cp_SiteMapNewColumn != null && node.cp_SiteMapNewColumn == "TRUE"){
		document.write('</td><td class="SiteMapPlainColumn">');
	}
	
	if (nodeLevel > 6)
		nodeLevel = 6;
		
	if (node.m_level > 0 || this.m_ShowHome)
	{
		var ds = new Array();
		var di = 0;

		if (this.m_ShowFocus && this.m_NavPath.length > 0 && node.m_level < this.m_NavPath.length)
		{
			if (this.m_NavPath[node.m_level] == node.m_id)
			{
				if (node.m_level > 0 || (node.m_level == 0 && this.m_NavPath.length == 1))
				{
					bSelected = true;
					nodeColor = this.m_FocusColor;
					nodeClass += '-focus';
				}
			}
		}
	
		if (node.m_level > 0)
			nodeClass += '-' + nodeLevel;
		
		
		if (node.m_level == 1){			
			ds[di++] = '<div';
			ds[di++] = ' class="' + nodeClass + '"';
			ds[di++] = '>';
			ds[di++] = '<span style="color: ' + nodeColor + ';"';
			ds[di++] = ' class="' + nodeClass + '"';
			ds[di++] = '>'
			ds[di++] = node.m_label;
			ds[di++] = '</span></div>';					
		}
		else{			
			ds[di++] = '<li>';											
			ds[di++] = '<a href="' + node.m_href + '"';
			
			if (nodeColor != '')
			{
				ds[di++] = ' style="color: ' + nodeColor + ';"';
				
				if (this.m_HoverColor != '')
				{
					ds[di++] = ' onmouseover="this.style.color=\'' + this.m_HoverColor + '\'"';
					ds[di++] = ' onmouseout="this.style.color=\'' + nodeColor + '\'"';
				}
			}
			ds[di++] = '>'			
			ds[di++] = '<div class="' + nodeClass + '">';
			ds[di++] = node.m_label;
			ds[di++] = '</div></a></li>';
		}
			
		document.write(ds.join(''));
	}
	
	// expand sub-levels (if any)
	for (var i = 0; i < node.m_subNodes.length; i++)
	{
		this.DisplayNode(node.m_subNodes[i]);
	}
}



