function enableMenu()
{
	uls = document.getElementsByTagName('UL');

	for (var i = 0; i < uls.length; i++){
		if (uls[i].className == 'dropdown'){
			var lis = uls[i].getElementsByTagName('li');

			for (var j = 0; j < lis.length; j++){
				if (lis[j].firstChild.nodeName.toLowerCase() == '#text') lis[j].removeChild(lis[j].firstChild);
				if (document.all){
					if (lis[j].lastChild.tagName == 'UL'){
						lis[j].onmouseover = function() { this.lastChild.style.display = 'block'; }
						lis[j].onmouseout = function() { this.lastChild.style.display = 'none'; }
						lis[j].onmouseover = function() { if (!hasClass(this.firstChild,'currentTop')) addClass(this.firstChild,'selectedTop'); }
						lis[j].onmouseout = function() { if (!hasClass(this.firstChild,'currentTop')) removeClass(this.firstChild,'selectedTop'); }
					}else if (lis[j].lastChild.previousSibling && lis[j].lastChild.previousSibling.tagName == 'UL'){
						lis[j].onmouseover = function() { if (!hasClass(this.firstChild.nextSibling,'currentTop')) addClass(this.firstChild.nextSibling,'selectedTop'); }
						lis[j].onmouseout = function() { if (!hasClass(this.firstChild.nextSibling, 'currentTop')) removeClass(this.firstChild.nextSibling,'selectedTop'); }
					}
				}else{
					if (lis[j].lastChild.previousSibling && lis[j].lastChild.previousSibling.tagName == 'UL'){
						lis[j].onmouseover = function()
						{
							if (this.firstChild.nodeName.toLowerCase() == '#text') this.removeChild(this.firstChild);
							if (!hasClass(this.firstChild,'currentTop')) addClass(this.firstChild,'selectedTop');
						}
						lis[j].onmouseout = function()
						{
							if (this.firstChild.nodeName.toLowerCase() == '#text') this.removeChild(this.firstChild);
							if (!hasClass(this.firstChild,'currentTop')) removeClass(this.firstChild,'selectedTop');
						}
					}
				}
			}
			addListener(window, 'load', preventMenuOut);
			addListener(window, 'resize', preventMenuOut);
		}
	}
}

function selectCurrent(menuId, currentItem, selectFirstIfNone)
{
	if (selectFirstIfNone == undefined){
		selectFirstIfNone = true;
	}
	if (currentItem == undefined || currentItem == ''){
		currentItem = window.location.href;
	}
	currentItem = currentItem.replace('http://','');
	currentItem = currentItem.replace(/\.html(\?[\w=&]*)?/i,'');
	var foundSelected = false;
	var links = document.getElementById(menuId).getElementsByTagName('a');
	for (var i = 0; i < links.length; i ++){
		var action = '';
		if (links[i].href){
			action = links[i].href.replace('http://','');
			action = action.replace(/\.html(\?[.]*)?/i,'');
		}
		if (action == currentItem){
			foundSelected = true;
			addClass(links[i],'currentTop');
			var parentLink = links[i].parentNode;
			while (parentLink){
				if (parentLink.nodeName.toLowerCase() == 'ul'){
					if (parentLink.previousSibling){
						if (parentLink.previousSibling.nodeName.toLowerCase() == 'a'){
							addClass(parentLink.previousSibling,'currentTop');
						}else if (parentLink.previousSibling.previousSibling){
							if (parentLink.previousSibling.previousSibling.nodeName){
								if (parentLink.previousSibling.previousSibling.nodeName.toLowerCase() == 'a'){
									addClass(parentLink.previousSibling.previousSibling,'currentTop');
								}
							}
						}
					}
				}
				parentLink = parentLink.parentNode;
			}
			break;
		}
	}
	if (!foundSelected){
		var tmp = currentItem.split('/');
		tmp.pop();
		if (tmp.length > 1){
			selectCurrent(menuId, tmp.join('/'), selectFirstIfNone);
		}else{
			if (selectFirstIfNone) addClass(links[0],'currentTop');
		}
	}
}

function preventMenuOut()
{
	uls = document.getElementsByTagName('UL');
	for (var i = 0; i < uls.length; i++){
		if (uls[i].className == 'dropdown'){
			var inner_uls = uls[i].getElementsByTagName('ul');
			for (j = 0; j < inner_uls.length; j++){
				var first_parent = inner_uls[j].parentNode;
				while (first_parent.parentNode && first_parent.nodeName.toLowerCase() != 'ul'){
					first_parent = first_parent.parentNode;
				}
				if (first_parent.className != 'dropdown'){
					var level = 2;
					var top = first_parent.parentNode;
					while (top.parentNode && top.parentNode.className != 'dropdown'){
						top = top.parentNode;
						if (top.nodeName.toLowerCase() == 'ul') level++;
					}
					var inner_size = getInnerSize();
					var sub_left = getSubMenuLeft(inner_uls[j]);
					var li = inner_uls[j].firstChild;
					while (li && li.nodeName.toLowerCase() != 'li'){
						li = li.nextSibling;
					}
					var a = li.firstChild;
					while (a && a.nodeName.toLowerCase() != 'a'){
						a = a.nextSibling;
					}
					var size = getElementSize(a);
					if ((sub_left + (size[0] * level)) > inner_size[0]){
						inner_uls[j].style.left = 'auto';
						inner_uls[j].style.right = '100%';
					}else if (inner_uls[j].style.left == 'auto'){
						inner_uls[j].style.left = '100%';
						inner_uls[j].style.right = 'auto';
					}
				}
			}
		}
	}
}

function getInnerSize()
{
	var w = 0, h = 0;
	if (typeof(window.innerWidth ) == 'number'){
		//Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	}else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		//IE 6+ in 'standards compliant mode'
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}else if (document.body && (document.body.clientWidth || document.body.clientHeight)){
		//IE 4 compatible
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	return [w,h];
}

function getSubMenuLeft(elm)
{
	var l = 0;
	while (elm.parentNode){
		l += (elm.offsetLeft) ? elm.offsetLeft : 0;
		if (elm == document.body) break;
		if (l > 0) break;
		elm = elm.parentNode;
	}

	return l;
}

function getElementSize(elm)
{
	var w = 0, h = 0;
	if (elm.offsetWidth && elm.offsetWidth > 0){
		w = elm.offsetWidth;
		h = elm.offsetHeight;
	}else if (elm.style.width && parseInt(elm.style.width) > 0){
		w = parseInt(elm.style.width);
		if (elm.style.paddingLeft && parseInt(elm.style.paddingLeft) > 0){
			w += parseInt(elm.style.paddingLeft);
		}
		if (elm.style.paddingRight && parseInt(elm.style.paddingRight) > 0){
			w += parseInt(elm.style.paddingRight);
		}
		if (elm.style.borderLeft && parseInt(elm.style.borderLeft) > 0){
			w += parseInt(elm.style.borderLeft);
		}
		if (elm.style.borderRight && parseInt(elm.style.borderRight) > 0){
			w += parseInt(elm.style.borderRight);
		}

		if (elm.style.height && parseInt(elm.style.height) > 0){
			h = parseInt(elm.style.height);
			if (elm.style.paddingTop && parseInt(elm.style.paddingTop) > 0){
				h += parseInt(elm.style.paddingTop);
			}
			if (elm.style.paddingBottom && parseInt(elm.style.paddingBottom) > 0){
				h += parseInt(elm.style.paddingBottom);
			}
			if (elm.style.borderTop && parseInt(elm.style.borderTop) > 0){
				h += parseInt(elm.style.borderTop);
			}
			if (elm.style.borderBottom && parseInt(elm.style.borderBottom) > 0){
				h += parseInt(elm.style.borderBottom);
			}
		}
	}else if (parseInt(getStyle(elm, 'width')) > 0){
		w = parseInt(getStyle(elm, 'width'));
		if (parseInt(getStyle(elm, 'padding-left')) > 0){
			w += parseInt(getStyle(elm, 'padding-left'));
		}
		if (parseInt(getStyle(elm, 'padding-right')) > 0){
			w += parseInt(getStyle(elm, 'padding-right'));
		}
		if (parseInt(getStyle(elm, 'border-left')) > 0){
			w += parseInt(getStyle(elm, 'border-left'));
		}
		if (parseInt(getStyle(elm, 'border-right')) > 0){
			w += parseInt(getStyle(elm, 'border-right'));
		}
		if (parseInt(getStyle(elm, 'height')) > 0){
			h = parseInt(getStyle(elm, 'height'));
		}
	}
	return [w,h];
}


