function menu(objectID)
{
	var self = this;
	
	this.theMenu = document.getElementById(objectID);
	this.theMenu.menuObject = this;
	this.visible = false;
	
	for (i = 0; i < this.theMenu.childNodes.length; i++)
	{
		var theMenuItem = this.theMenu.childNodes[i];
		
		if (theMenuItem.nodeName.toLowerCase() == "li" && (objectID != "menu" ||
			(objectID == "menu" && theMenuItem.id == "menuProducts") ||
			(objectID == "menu" && theMenuItem.id == "menuServices") ||
			(objectID == "menu" && theMenuItem.id == "menuSupport") ||
			(objectID == "menu" && theMenuItem.id == "menuContact"))
		   )
		{
			var theLink = getChildElement(theMenuItem, "a");

			if (theLink != null)
			{
				theLink.onclick = function()
					{
						self.toggleVisibility(this);
						return false;
					};
			}
			
			theMenuItem.onmouseover = function()
				{
					self.toggleVisibility(this, true);
					return true;
				};
		}
	}
		
	return true;
}




menu.prototype.closeChildren = function()
{

	for (var i = 0; i < this.theMenu.childNodes.length; i++)
	{
		if (this.theMenu.childNodes[i].nodeName.toLowerCase() == "li")
		{
			this.theMenu.childNodes[i].className = this.theMenu.childNodes[i].className.removeClass("visible");
		}
	}
	
	return true;
}





menu.prototype.toggleVisibility = function(theMenuItem, mouseStatus)
{
	var self = this;

	if (this.visible && !mouseStatus)
	{
		this.theMenu.className = this.theMenu.className.removeClass("visible");
		this.closeChildren();
		
		document.onclick = null;
		
		this.visible = false;
	}
	else if (typeof(theMenuItem) == "object" && ((mouseStatus && this.visible) || !mouseStatus))
	{
		if (theMenuItem.nodeName.toLowerCase() == "a")
		{
			theMenuItem = theMenuItem.parentNode;
		}
		
		this.closeChildren();
		
		this.theMenu.className = this.theMenu.className.addClass("visible");
		theMenuItem.className = theMenuItem.className.addClass("visible");
		
		setTimeout(function()
			{
				var innerSelf = self;
				
				document.onclick = function()
					{
						innerSelf.toggleVisibility();
						
						return true;
					};
			}, 100);
			
			this.visible = true;
	}
	
	return true;
}




function getChildElement(theParent, elementName, thePosition)
{
	var theElement = null;
	
	if (typeof(thePosition) != "int")
	{
		thePosition = 1;
	}
	
	for (var i = 0, j = 1; i < theParent.childNodes.length; i++)
	{
		if (theParent.childNodes[i].nodeName.toLowerCase() == elementName)
		{
			if (j == thePosition)
			{
				theElement = theParent.childNodes[i];
				
				break;
			}
			else
			{
				j++;
			}
		}
	}
	
	return theElement;
}




String.prototype.addClass = function(theClass)
{
	var targetClass = "";
	
	if (this == "")
	{
		targetClass = theClass;
	}
	else if (!this.classExists(theClass))
	{
		targetClass = this + " " + theClass;
	}
	else
	{
		targetClass = this;
	}
	
	return targetClass;
}




String.prototype.classExists = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	if (regExpression.test(this))
	{
		return true;
	}
	
	return false;;
}




String.prototype.removeClass = function(theClass)
{
	var regString = "(^| )" + theClass + "(\W*)";
	var regExpression = new RegExp(regString);
	var targetClass = "";

	targetClass = this.replace(regExpression, "$2");
	
	return targetClass;
}
