function swapOver(obj, className, e)  {
    try {
        obj.className = className;
        var ul = getChildElementByTagName(obj, 'UL')
        if (ul) {                
            ul.style.top = obj.offsetTop.toString() + 'px';
            ul.style.left = (obj.clientWidth).toString() + 'px';                        
        }   
    } catch(e) {            
        //do nothing
    }      
}  

function swapOut(obj, className, e)  {  
    try {      
        var parentMenuFrom = getParentElementByTagName(obj, 'UL');
        var childMenuFrom = getChildElementByTagName(obj, 'UL');
        var to = (e.relatedTarget||e.toElement);   
        var parentMenuTo = getParentElementByTagName(to, 'UL');   
        //if moused to is nothing or there is no parent menu for the mouse to element, swap classes   
        if (obj&&(!to||!parentMenuTo)) { 
            obj.className = className; 
            return true;
        } 
        var toParentLi = getParentElementByTagName(to, 'LI');
        //if the parent element of moused to is not the list item obj 
        //and the parent menu of to is not the child menu of from 
        if (obj && (toParentLi != obj && parentMenuTo != childMenuFrom)) { 
            //at this point we have moused out to another menu item, if we are doing anything 
            //other than going deeper into the menu then swap the classes                                    
            switch(parentMenuTo.className) {
                case 'subMenu level2':
                    if (parentMenuFrom.className != 'menuRoot') {
                        obj.className = className;
                        return true;                           
                    }
                    break;
                case 'subMenu level3':
                    if (parentMenuFrom.className != 'subMenu level2' && parentMenuFrom.className != 'menuRoot') {
                        obj.className = className;
                        return true;                            
                    }
                    break;
                default:
                    obj.className = className; 
                    return true;                       
                    break;
            } 
        }  
        return false;             
    } catch(e) {
        //do nothing
    }       
}  

function getParentElementByTagName(node,tagName) {   
    try {     
        if (!node) {
            return node;
        } 
        else {
            if (!tagName) {
                return node.parentNode;
            }
            else {
                if (node.tagName==tagName) {
                    return node;      
                } 
                else {                   
                    return getParentElementByTagName(node.parentNode,tagName);
                } 
            }
        }   
    } catch(e) {
        //do nothing        
    }    
}  

function getChildElementByTagName(node,tagName) {
    try {
        if (!node||!tagName) {
            return node;
        } 
        else { 
            for (var i = 0; i < node.childNodes.length; i++) {
                if (node.childNodes[i].tagName == tagName) {return node.childNodes[i];}
            }       
        }  
    } catch(e) {
        //do nothing
    }            
}