var isFirefox = 0;
var isIE = 0;
var isRTL = 0;
var isAttach = 0;
var isListen = 0;

function identify()
{
    if (window.attachEvent)
        isAttach = 1;
    if (window.addEventListener)
        isListen = 1;
    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
        isFirefox = new Number(RegExp.$1);
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        isIE = new Number(RegExp.$1);
        // if (isIE == 8)
        //    isRTL = 1;
    }
}

function setPos(els, ref)
{
    if (els.length > 0) {
	    if (els[0].offsetWidth < ref.offsetWidth)
	        els[0].style.width = ref.offsetWidth + "px";
	    if (isRTL) {
            els[0].style.left = ref.parentNode.offsetWidth - ref.offsetLeft - els[0].offsetWidth + "px";
    	    els[0].style.top = ref.offsetTop + ref.offsetHeight + "px";
        } else {
            els[0].style.left = ref.offsetLeft + (ref.offsetWidth - els[0].offsetWidth) + "px";
    	    els[0].style.top = ref.offsetTop + ref.offsetHeight - 1 + "px";
        }
	}
}

menuHover = function() {
    var sfEls = document.getElementById("menu").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" menuHover";
            setPos(this.getElementsByTagName("UL"), this);
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" menuHover\\b"), "");
        }
    }
}

identify();
if (isAttach) {
    window.attachEvent("onload", menuHover); 
} else if (isListen) {
    window.addEventListener("DOMContentLoaded", menuHover, false);
} else {
    alert("Unsupported browser... Sorry");
}
