function get_file_name(s)
{
	var href_arr = s.split('/');
	
	return href_arr[href_arr.length-1];
}

function menu_item(nm, cls, color, ref, sub_menu_cnt)
{
	this.name = nm;					// name to display
	this.css_class = cls;			// class of the cell
	this.highlight = color;			// color of cell when highlighted

	this.href = null;	
	if (ref != null)
	{
		var ref_file = get_file_name(ref);
		var cur_file = get_file_name(location.href);
		if (cur_file == 'index.htm' || ref.indexOf('mailto') == 0)
		{
			this.href = ref;				// to use with onclick event
		}
		else if (ref_file == cur_file)
		{
			this.href = ref_file;
		}
		else
		{
			this.href = '../' + ref;				// to use with onclick event
		}
	}
	
	if (sub_menu_cnt > 0)
	{
		this.menu = new menu(sub_menu_cnt,'-');
	}
	else
	{
		this.menu = null;
	}
	this.show = show_menu_item;		// method to show menu cell
}

function get_label(instr)
{
	var s = instr;
	var pos = s.indexOf(' ');
	while (pos > 0)
	{

	  s = s.substr(0,pos) + '_' + s.substr(pos+1);
	  
	  pos = s.indexOf(' ');
	}
	
	pos = s.indexOf('&nbsp;');
	while (pos > 0)
	{
	  s = s.substr(0,pos) + '_' + s.substr(pos+6);
	  
	  pos = s.indexOf(' ');
	}
	
	return s.toLowerCase();
}

function show_menu_item()
{
	var menu_id = get_label(this.name);
	
	with (document)
	{
		write('<td class="' + this.css_class + '"');
		if (this.href != null && this.href != '')
		{
			write(' style="cursor:pointer" onclick="location.href=' + "'" + this.href + "'" + ';"');
		}
		else
		{
			write(' style="cursor:default"');
		}
		if (this.menu == null)
		{
			write(' onmouseover="highlight_cell(this,' + "'" + this.highlight + "'" + ');"');
			write(' onmouseout="highlight_cell(this,' + "''" + ');"');
		}
		else
		{
			write(' onmouseover="highlight_cell(this,' + "'" + this.highlight + "'); showmenu('" + menu_id + "'" + ');"');
			write(' onmouseout="highlight_cell(this,' + "''); hidemenu('" + menu_id + "');" + '"');
			
			if (this.css_class == 'navbar_item')
			{
				write(' width=' + menu_width);
			}
  		}
		write('>');
		if (this.css_class == 'navbar_item')
		{
			write('<div align="center">');
		}
		write(this.name);
		if (this.css_class == 'navbar_item')
		{
			write('</div>');
		}
		if (this.menu != null)
		{
			if (this.css_class == 'navbar_item')
			{
				show_menu(this.menu, 'menu', menu_id);
			}
			else
			{
				show_menu(this.menu, 'submenu', menu_id);
			}
		}
		writeln('</td>');
	}
}

function menu(cnt, initstr)
{
  this.length = cnt;
  for (var i=1; i<=cnt; i++)
  {
    this[i] = initstr;
  }
}

function show_navbar(navbar)
{
	with (document)
	{
		writeln('<table class="navbar" align="center"');
		if (!cell_space)
		{
			write(' cellspacing=0');
		}
		write('>');
		writeln('<tr>');
		for( var i = 1; i <= navbar.length; i++)
		{
			navbar[i].show();
	    }
		writeln('</tr>');
    	writeln("</table>");
    }
}

function show_menu(menu,cls,id)
{
	with (document)
	{
		writeln();
		writeln('<table class="' + cls + '" id="' + id + '"');
		if (!cell_space)
		{
			write(' cellspacing=0');
		}
		write('>');
		for( var i = 1; i <= menu.length; i++)
		{
			write('<tr>');
			menu[i].show();
			writeln('</tr>');
	    }
	    writeln('</table>');
	}
}

function highlight_cell(cell,color)
{
	cell.style.backgroundColor=color;
}

function showmenu(elmnt)
{
	document.getElementById(elmnt).style.visibility="visible";
}

function hidemenu(elmnt)
{
	document.getElementById(elmnt).style.visibility="hidden";
}

function get_base_uri()
{
	var base_uri = "http://www.firstcc.org/";
	
    if (location.href.toLowerCase().indexOf('c:') != 0)
	{
		base_uri = "file://C:/Users/Debbie/Documents/CEY/Firstcc_web/";
	}
	else if (location.href.toLowerCase().indexOf('d:') != 0)
	{
		base_uri = "file://d:/firstcc/";
	}
	else if (location.href.toLowerCase().indexOf('e:') != 0)
	{
		base_uri = "file://e:/firstcc/";
	}
	else if (location.href.toLowerCase().indexOf('f:') != 0)
	{
		base_uri = "file://f:/firstcc/";
	}
	
	return base_uri;
}
