/////////////////////////////////////////////////////////////////////////////
// Function : IS_2006_Site_Map
// 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...

function IS_2006_Site_Map(strTextColor, strHoverColor, strFocusColor, strClassName, strShowHome, strShowFocus)
{
	this.m_TextColor  = '';
	this.m_HoverColor = '';
	this.m_FocusColor = '';
	this.m_ClassName  = 'IS_2006_Site_Map';
	
	this.m_ShowHome   = false;
	this.m_ShowFocus  = false;	
	
	this.m_curCol	  = 0;
	this.m_maxCol	  = 3;
	
	this.m_NavPath    = g_navNode_Path;
		
	IS_2006_Site_Map.prototype.Display = IS_2006_Site_Map_Display;
	IS_2006_Site_Map.prototype.DisplayNode = IS_2006_Site_Map_DisplayNode;
	IS_2006_Site_Map.prototype.GetHeading = IS_2006_Site_Map_GetHeading;
	IS_2006_Site_Map.prototype.IsService = IS_2006_Site_Map_IsService;
	IS_2006_Site_Map.prototype.IndentNode = IS_2006_Site_Map_IndentNode;
	IS_2006_Site_Map.prototype.GetColumnNum = IS_2006_Site_Map_GetColumnNum;
	
	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;
		
	/*Create Service Node*/
	this.ServiceNode = new Object();
	this.ServiceNode.m_level = 1;
	this.ServiceNode.m_label = 'Services';
	this.ServiceNode.m_href = '#';
	this.ServiceNode.m_subNodes = new Array();
}

function IS_2006_Site_Map_Display (node)
{
	var index = 0;
	var ServiceIndex = 1;
	
	/*Put Services in the Service Node*/
	for(var i = 0; i < node.m_subNodes.length; i++) {
		while(this.IsService(node.m_subNodes[i])) {
			//node.m_subNodes[i].m_level += 1;
			this.IndentNode(node.m_subNodes[i]);
			this.ServiceNode.m_subNodes[index] = node.m_subNodes[i];
			index++;
			
			for(var j = i + 1; j < node.m_subNodes.length; j++) {
				node.m_subNodes[j - 1] = node.m_subNodes[j];
				node.m_subNodes[j] = null;
			}
		}
	}
	
	/*Make room for Services*/
	for(var k = node.m_subNodes.length - 1; k > ServiceIndex; k--) {
		node.m_subNodes[k] = node.m_subNodes[k - 1];
	}
	
	node.m_subNodes[ServiceIndex] = this.ServiceNode;
	
	/*Resize the Array*/
	index = 0;
	var tempNodes = new Array();
	while(node.m_subNodes[index] != null) {
		tempNodes[index] = node.m_subNodes[index];
		index++;
	}
	
	node.m_subNodes = tempNodes;

	document.write ('<div class="' + this.m_ClassName + '"');
	
	if (this.m_TextColor != '')
		document.write (' style="color: ' + this.m_TextColor + ';"');
		
	document.write ('>');

	this.DisplayNode(node);
	
	document.write ('</div>');
}

function IS_2006_Site_Map_DisplayNode(node)	
{
	var nodeColor = this.m_TextColor;
	var nodeClass = this.m_ClassName;
	var nodeLevel = node.m_level;
	
	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;

		ds[di++] = '<div';
		ds[di++] = ' class="' + nodeClass + '"';
		ds[di++] = '>';
				
		ds[di++] = '<a href="' + node.m_href + '"';
		
		ds[di++] = ' class="' + nodeClass + this.GetHeading(node) + '"';
		
		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++] = node.m_label;
		ds[di++] = '</a></div>';
		
		document.write(ds.join(''));
	}
	
	// expand sub-levels (if any)
	for (var i = 0; i < node.m_subNodes.length; i++)
	{
		if(node.m_level == 0) {
			var newCol = this.GetColumnNum(node.m_subNodes[i]);
			if(this.m_curCol != newCol) {
				this.m_curCol = newCol;
				document.write('<div class="IS_2006_Site_Map_Container-' + newCol + '">');
			}
			
			document.write('<div class="IS_2006_Site_Map_Group">');
		
			this.DisplayNode(node.m_subNodes[i]);
			
			document.write('</div>');
		
			/*Check ahead*/
			if(i + 1 < node.m_subNodes.length) {
				if(this.m_curCol != this.GetColumnNum(node.m_subNodes[i+1])) {
					document.write('</div>');
				}
			} else {
				document.write('</div>');
			}
		} else {
			this.DisplayNode(node.m_subNodes[i]);
		}
	}
}

function IS_2006_Site_Map_GetHeading(node) {
	switch(node.m_label) {
		case 'Company':			return ' Company';
		case 'Conversion':		return '';
		case 'Consulting':		return '';
		case 'Integration':		return '';
		case 'Training':		return '';
		case 'Customer Success':	return ' CustomerSuccess';
		case 'Support':			return ' Support';
		case 'Products':		return ' Products';
		case 'News':			return ' NewsEvents';
		case 'Events':			return ' NewsEvents';
		case 'Services':		return ' Services';
		default:			return '';
	}
}

function IS_2006_Site_Map_IsService(node) {
	if(node == null) return false;

	switch(node.m_label) {
		case 'Conversion':		return true;
		case 'Consulting':		return true;
		case 'Integration':		return true;
		case 'Training':		return true;
		default:			return false;
	}
}

function IS_2006_Site_Map_GetColumnNum(node) {
	switch(node.m_label) {
		case 'Company':			return 1;
		case 'Services':		return 2;
		case 'Customer Success':	return 2;
		case 'Support':			return 2;
		case 'Products':		return 3;
		case 'News':			return 4;
		case 'Events':			return 4;
		default:			return 0;
	}
}

function IS_2006_Site_Map_IndentNode(node) {
	node.m_level += 1;
	
	for(var i = 0; i < node.m_subNodes.length; i++) {
		this.IndentNode(node.m_subNodes[i]);
	}
}
