	
	
// Javascript menubar
// Version: 	1.5
// Date: 		June 5, 2006
// Author: 		Peter Hrynkow (peter@herraincoskipp.com)



//
// New in 1.5
//	Whitespace removal
// vertical menu mode
//



// New in 1.3.0
// Removed JS data model, now using html model. This will allow search engines 
// to spider links properly. 
// minimized stylesheet



// New in 1.2.0
// OOP
// Absolute positioned menu items
// Up or down menu
// cleaned up code
// 



// Browser support
// Safari 1.0 	<
// Firefox 1.0 	<
// IE Mac 5.1 	<	 
// IE PC 6.0 	<
// Netscape 7.0 <




// Optionally suppress any minor errors that might occur
// IE might generate a few non-fatal errors that are annoying.

/*
function no_error()
{ return true; }
window.onerror=no_error;
document.alerts = 0
*/


var Menu = function()
{
	this.openMenus = new Array();
}


Menu.prototype.openMenus;							// Array		stores all open menus
Menu.prototype.mo_time;								// Number	
Menu.prototype.h_space;								// Number	indicates horizontal space between menus
Menu.prototype.v_space;								// Number	indicates vertical space between menus
Menu.prototype.container 							// String	id of the container DIV
Menu.prototype.mode = "horizontal"				// String	"up" or "down" refereing to the direction menus are displayed
Menu.prototype.direction = "down"				// String	"up" or "down" refereing to the direction menus are displayed
Menu.prototype.selectedNodes						// Array		selected nodes
Menu.prototype.menuObj;								// Object	reference of the container div element


Menu.prototype.draw = function()
{

	this.selectedNodes = new Array();

	this.menuObj = document.getElementById(this.container);
	
	var markup = this.menuObj.innerHTML
	
	//
	// clean up menu markup, removing white space
	// 1. remove breaks
	// 2. remove tabs
	// 3. remove double-spaces
	//
	

	markup = markup.replace(/\n/g,"");
	markup = markup.replace(/\r/g,"");
	markup = markup.replace(/\t/g,"");
	markup = markup.replace(/\s\s/g,"");
	

	this.menuObj.innerHTML = markup
	this.createMenu(this.menuObj)
	this.menuObj.style.visibility = "visible"		
}


	

	
	
Menu.prototype.createMenu = function(div)
{
	var sn = div.lastChild
	
	
	if(!sn || sn.nodeName.toUpperCase() != "DIV")
	{	
		return;
	}
	
	
	sn.style.position = "absolute";
	sn.name = "subNodes"



	if(div != this.menuObj)
	{
		sn.style.visibility = "hidden"
	}

	
	var menu = sn.childNodes
	
	// begin looping through submenus
	for(var i=0;i<menu.length;i++)
	{

		var c = menu[i];
		
		c.style.position = "absolute"
		
	
	
		a = c.firstChild
		c.button = a
		
		a.style.position = "absolute"
		
		
		
		
		if(!a.className){
			var _class = "node"
		}else{
			var _class = a.className
		}
			
			
		a.className_up = _class
		a.className_over = "node_over " + _class
		a.className_down = "node_down " + _class
		a.className_selected = "node_selected " + _class
		a.className = _class;
		
		

		
		a.style.display="block";
		a.owner = this
		
		
		
		//
		// determine item position
		//
		var x = 0
		var y = 0
		
		
		switch(this.mode)
		{
	
			//
			// vertical positioning
			//
			case "vertical":
				if(div == this.menuObj)
				{
					var button			
					if(c.previousSibling)
					{
						y = c.previousSibling.button.offsetHeight + c.previousSibling.offsetTop + this.v_space
					}
				}else{
					switch(this.direction)
					{
						case "down":
							if(div.parentNode.parentNode == this.menuObj)
							{
								y = -3//c.parentNode.parentNode.button.offsetHeight - c.button.offsetHeight
								
							}
							if(c.previousSibling)
							{
								y = c.previousSibling.offsetTop + c.previousSibling.button.offsetHeight
							}
						break;
						case "up":
							if(div.parentNode.parentNode == this.menuObj)
							{
								y = -c.button.offsetHeight
							}
							if(c.previousSibling)
							{
								y = c.previousSibling.offsetTop - c.button.offsetHeight
							}
						break;
					}
					x = div.button.firstChild.offsetWidth
				}
			break;
	
	
			//
			// horizontal positioning
			//
			case "horizontal":
				if(div == this.menuObj)
				{
					var button			
					if(c.previousSibling)
					{
						x = c.previousSibling.button.offsetWidth + c.previousSibling.offsetLeft + this.h_space
					}
				}else{
				
					switch(this.direction)
					{
						case "down":
							if(div.parentNode.parentNode == this.menuObj)
							{
								y = c.parentNode.parentNode.button.offsetHeight
							}
							if(c.previousSibling)
							{
								y = c.previousSibling.offsetTop + c.button.offsetHeight
							}
						break;
						case "up":
							if(div.parentNode.parentNode == this.menuObj)
							{
								y = -c.button.offsetHeight
							}
							if(c.previousSibling)
							{
								y = c.previousSibling.offsetTop - c.button.offsetHeight
							}
						break;
					}
					
					if(div.parentNode.parentNode != this.menuObj)
					{
						x = div.button.offsetWidth
					}
				}
			break;
		}
		
		
		//
		// set position values
		//
		c.style.left = x + "px"
		c.style.top = y + "px"


		
		// Add event handlers to the menu item		
		a.onmouseover = function()
		{
			
			if(this.className.indexOf("selected")<0)
			{
				this.className = this.className_over
			}
		
			if(this.owner.mo_time)
			{
				window.clearTimeout(this.owner.mo_time)
			}
			this.owner.closeMenus()
			this.owner.showMenu(this)

		}
		
		a.onmouseout = function()
		{
			
			if(this.className.indexOf("selected")<0)
			{
				this.className = this.className_up			
			}
			this.owner.mo_time = window.setTimeout("closeMenus()",500)

		}
		a.onclick = function()
		{
			/*if(this.className.indexOf("selected")<0)
			{
				this.className = this.className_over
			}*/
			
			/*if(this.owner.mo_time)
			{
				window.clearTimeout(this.owner.mo_time)
			}
			this.owner.closeMenus()
			this.owner.showMenu(this)*/

		
			//for(var i=0;i<this.owner.selectedNodes.length;i++)
			//{
			//	this.owner.selectedNodes[i].className = this.owner.selectedNodes[i].className_up
			//}
		//	this.owner.makeNodeActive(this.parentNode);
		}
		
		
		
		

		if(window.location.href.indexOf(a.href)>-1)
		{
			this.makeNodeActive(a.parentNode);
		}
		
		
		document["menu_tmp"] = this

		window.closeMenus = function()
		{
			document["menu_tmp"].closeMenus()
		}

		//
		// disable link on nodes with sub-items
		//
	/*
		if(c.lastChild != a)
		{
			a.href = "javascript:void()";
		}
	*/
		
		// Recursively build any submenus
		this.createMenu(c)
	
	}
		
}
	
	
	
Menu.prototype.makeNodeActive = function(node)
{

	a = node.firstChild
	//a.href = "javascript:void()";
	if(a.nodeName == "A")
	{		
		a.className = a.className_selected
		//alert(a + "," + a.className_selected)
		
		this.selectedNodes[this.selectedNodes.length] = a
	}

	if(node.parentNode != this.menuObj)
	{
		this.makeNodeActive(node.parentNode)
	}
}



	
	
	
	
	
	
Menu.prototype.showMenu = function(node)
{
	var p = node.parentNode
	this.revealRecursive(p)
}
	
	
	
	
	
//Closes all open menus
Menu.prototype.closeMenus = function()
{
	for(var i=0;i<this.openMenus.length;i++)
	{
	
		var m = this.openMenus[i]
		this.setVisibility(m,false)
		
		//
		// send menu to back
		//
		m.parentNode.style.zIndex = 0
		
		
		if(m.parentNode.button.className.indexOf("selected")<0)
		{
			m.parentNode.button.className = m.parentNode.button.className_up
		}
	}
	this.openMenus = new Array()
}
	
	
	
	
	
// Make a menu and its path to the base visible.

Menu.prototype.revealRecursive = function(node)
{
	
	this.showSubNodes(node)	

	if(node.parentNode != this.menuObj)
	{
		this.revealRecursive(node.parentNode)
	}
}




// Make subNodes visible and push all open menus into the openMenus array

Menu.prototype.showSubNodes = function(node)
{


	if(node.childNodes.length > 1)
	{
		var nub = node.lastChild
		if(nub.name == "subNodes")
		{
		
			this.setVisibility(nub,true)
			this.openMenus[this.openMenus.length] = nub
			
			//
			// bring menu to front
			//
			nub.parentNode.style.zIndex = 100
			
			if(node.button.className.indexOf("selected")<0)
			{
				node.button.className = node.button.className_over
			}
		}
	}
}



// Set the visibility of a menu item
Menu.prototype.setVisibility = function(obj,val)
{
	obj.style.visibility = val ? "visible" : "hidden";
}










Array.prototype.search = function(value)
{
	for(i=0;i<this.length;i++)
	{
		if(this[i] == value) return i
	}
}





function popWin(u,n,o)
{
	var pop = window.open(u,n,o);

}

	
	
	
