function child_list_show(obj)
{
	for (i = 0; i < obj.childNodes.length; i++) {
		if (obj.childNodes[i].nodeType == 1) {
			if (obj.childNodes[i].tagName.toLowerCase() == 'ul') {
				obj.childNodes[i].style.display = 'block';
			}
		}
	}
}

function child_list_hide(obj)
{
	for (i = 0; i < obj.childNodes.length; i++) {
		if (obj.childNodes[i].nodeType == 1) {
			if (obj.childNodes[i].tagName.toLowerCase() == 'ul') {
				obj.childNodes[i].style.display = 'none';
			}
		}
	}
}

function follow_link(obj)
{
	for (i = 0; i < obj.childNodes.length; i++) {
		if (obj.childNodes[i].nodeType == 1) {
			if (obj.childNodes[i].tagName.toLowerCase() == 'a') {
				if (obj.childNodes[i].href != null) {
					var addr = obj.childNodes[i].href;
					if (addr != null) {
						//alert(addr);
						window.location = addr;
					} else {
						//alert("No href attribute.");
					}
				}
			}
		}
	}
}

function has_link_child(obj)
{
	for (i = 0; i < obj.childNodes.length; i++) {
		if (obj.childNodes[i].nodeType == 1) {
			if (obj.childNodes[i].tagName.toLowerCase() == 'a') {
				if (obj.childNodes[i].href.charAt(obj.childNodes[i].href.length - 1) != '#') {
					return true;
				}
			}
		}
	}
	
	return false;
}

function child_link_set_class(obj, classValue)
{
	for (i = 0; i < obj.childNodes.length; i++) {
		if (obj.childNodes[i].nodeType == 1) {
			if (obj.childNodes[i].tagName.toLowerCase() == 'a') {
				obj.childNodes[i].className = classValue;
				break;
			}
		}
	}
	
	return false;
}

function activate_nested_menus()
{
	var lists;
	var activatable_list_count = 0;
	
	lists = document.getElementsByTagName('ul');
	for (var i = 0; i < lists.length; i++) {
		if (lists[i].className == 'nested_menu') {
			activatable_list_count++;
			
			var list_items = lists[i].getElementsByTagName('li');
			for (j = 0; j < list_items.length; j++) {
				list_items[j].onmouseover = function() {
					this.className = 'hover';
					child_link_set_class(this, 'hover');
					child_list_show(this);
				}
				list_items[j].onmouseout = function() {
					this.className = '';
					child_link_set_class(this, '');
					child_list_hide(this);
				}
				
				list_items[j].style.cursor = "pointer";
				if (has_link_child(list_items[j]) == true) {
					list_items[j].onclick = function(e) {
						if (!e) {
							var e = window.event;
						}
						
						follow_link(this);
						e.cancelBubble = true;
					}
				}
			}
		}
	}
	
	//alert("Activatable lists: " + activatable_list_count);
}

addLoadEvent(activate_nested_menus);
