var objNavMenu = null;
var prevObjNavMenu = null;
var prevObjDropMenu = null;
////// link styles
var bgLinkColor = '#D4D0C8';
var bgLinkHover = '#ffffff'
var bgLinkActive = '#444444'
var linkColor = '#000000'
var linkHover = '#444444'
var linkActive = '#ffffff'
			
var isIE = null;
if (navigator.appName.indexOf('Microsoft Internet Explorer') != -1) isIE=1;

function initDropMenu () 
{
    document.onclick = hideDropMenu;
    for (i=1; i<=numDropMenu; i++) {
        menuName = 'dropMenu' + i;
        navName = 'navMenu' + i;
        objDropMenu = document.getElementById(menuName);
        objNavMenu = document.getElementById(navName);
        objDropMenu.style.visibility = 'hidden';
        objNavMenu.onmouseover =  showDropMenu;//menuHover;
        objNavMenu.onmouseout = menuOut;
        objNavMenu.onclick = showDropMenu;
    }
    objNavMenu = null;
    return;
}


function  menuHover(e) {
    document.onclick = null;
    hoverObjNavMenu = document.getElementById(this.id);
    if (hoverObjNavMenu != objNavMenu) {
        hoverObjNavMenu.style.color = linkHover;
	hoverObjNavMenu.style.backgroundColor = bgLinkHover;
    }		
}
			
function menuOut (e) {
    document.onclick = hideDropMenu;
    outObjNavMenu = document.getElementById(this.id);
    if (outObjNavMenu != objNavMenu) {
        outObjNavMenu.style.color = linkColor;
        outObjNavMenu.style.backgroundColor = bgLinkColor;
    }
}
			
function showDropMenu(e) {
    menuName = 'drop' + this.id.substring(3,this.id.length);
    objDropMenu = document.getElementById(menuName);
    if (prevObjDropMenu == objDropMenu) {
        hideDropMenu();
	return;
    }
    if (prevObjDropMenu != null) hideDropMenu();
        objNavMenu = document.getElementById(this.id);
        if ((prevObjNavMenu != objNavMenu ) || (prevObjDropMenu == null)) {
            objNavMenu.style.color = linkActive;
            objNavMenu.style.backgroundColor = bgLinkActive;
	}
				
	if (objDropMenu) {
            xPos = objNavMenu.offsetParent.offsetLeft + objNavMenu.offsetLeft;
            yPos = objNavMenu.offsetParent.offsetTop + objNavMenu.offsetParent.offsetHeight;

            if (isIE) {
                yPos -= 1;
		xPos -= 6;
            }

            objDropMenu.style.left = xPos + 'px';
            objDropMenu.style.top = yPos + 'px';
            objDropMenu.style.visibility = 'visible';
            prevObjDropMenu = objDropMenu;
            prevObjNavMenu = objNavMenu;
	}
			
}
			
function hideDropMenu() {
    document.onclick = null;
    if (prevObjDropMenu) {
        prevObjDropMenu.style.visibility = 'hidden';
	prevObjDropMenu = null;
	prevObjNavMenu.style.color = linkColor;
	prevObjNavMenu.style.backgroundColor = bgLinkColor;
    }
    objNavMenu = null;
}
			
function changeParentBg(obj, color)
{
    var parent;
    if (obj.parentNode) //W3C
    {
        parent = obj.parentNode;
    }
    else
    if (obj.parentElement) //IE
    {
        parent = obj.parentElement;
    }
    parent.style.backgroundColor = color;
}

function changeParentColor(obj, color)
{
    var parent;
    if (obj.parentNode) //W3C
    {
        parent = obj.parentNode;
    }
    else
    if (obj.parentElement) //IE
    {
        parent = obj.parentElement;
    }
    parent.style.color = color;
}


function linkOver(obj)
{
    var bgOver = bgLinkActive;
    changeParentBg(obj, bgOver);
    obj.style.alinkColor = '#FFFFFF';
    hideAllDropMenu();
}

function linkOut(obj)
{
    var bgLink = bgLinkColor;
    changeParentBg(obj, bgLink);
    obj.style.alinkColor = linkHover;
}

function hideAllDropMenu()
{
    var x;
    var y;
    var z;
    var zz;
    for (i=1; i<=numDropMenu; i++) 
    {
        x = 'dropMenu' + i;
        y = document.getElementById(x);
        y.style.visibility = 'hidden';

        z = 'navMenu' + i;
        zz = document.getElementById(navName);

        zz.style.color = '#000000';
        zz.style.backgroundColor= bgLinkColor;
    }

    objNavMenu = null;
    prevObjNavMenu = null;
    prevObjDropMenu = null;
}

