﻿var inApplicationsHdr, inApplicationsMenu, inPartnersHdr, inPartnersMenu, inServicesHdr, inServicesMenu, inCompanyHdr, inCompanyMenu, inContactHdr, inContactMenu;

function displayMenu(name) {
    document.getElementById('td' + name).style.backgroundColor = '#dfdfdf';
    document.getElementById('td' + name).style.color = '#3985d4';
    document.getElementById('menu' + name).style.left = (findPosX(document.getElementById('img' + name)) - parseInt(document.getElementById('menu' + name).style.width) - 14) + 'px';
    document.getElementById('menu' + name).style.visibility = 'visible';
}

function displayMenuShadow(name) {
    document.getElementById('menu' + name + 'Shadow').style.left = (findPosX(document.getElementById('img' + name)) - parseInt(document.getElementById('menu' + name).style.width) - 18) + 'px';
    document.getElementById('menu' + name + 'ShadowBottom').style.left = (findPosX(document.getElementById('img' + name)) - parseInt(document.getElementById('menu' + name).style.width) - 9) + 'px';
    document.getElementById('menu' + name + 'ShadowBottomLeft').style.left = (findPosX(document.getElementById('img' + name)) - parseInt(document.getElementById('menu' + name).style.width) - 18) + 'px';
    document.getElementById('menu' + name + 'ShadowRight').style.left = (findPosX(document.getElementById('img' + name))) + 'px';
    document.getElementById('menu' + name + 'ShadowBottomRight').style.left = (findPosX(document.getElementById('img' + name)) + 1) + 'px';
    document.getElementById('menu' + name + 'Shadow').style.visibility = 'visible';
    document.getElementById('menu' + name + 'ShadowBottom').style.visibility = 'visible';
    document.getElementById('menu' + name + 'ShadowBottomLeft').style.visibility = 'visible';
    document.getElementById('menu' + name + 'ShadowRight').style.visibility = 'visible';
    document.getElementById('menu' + name + 'ShadowBottomRight').style.visibility = 'visible';
}

function displayMenus() {

    hideMenus();

    if (inPartnersHdr || inPartnersMenu) {
        displayMenu('Partners');
    }

    if (inServicesHdr || inServicesMenu) {
        displayMenu('Services');
    }

    if (inCompanyHdr || inCompanyMenu) {
        displayMenu('Company');
    }

    if (inContactHdr || inContactMenu) {
        displayMenu('Contact');
    }
}

function displayMenuShadows() {

    hideMenus();

    if (inPartnersHdr || inPartnersMenu) {
        displayMenuShadow('Partners');
    }

    if (inServicesHdr || inServicesMenu) {
        displayMenuShadow('Services');
    }

    if (inCompanyHdr || inCompanyMenu) {
        displayMenuShadow('Company');
    }

    if (inContactHdr || inContactMenu) {
        displayMenuShadow('Contact');
    }
}

function hideMenu(name) {
    document.getElementById('td' + name).style.backgroundColor = '';
    document.getElementById('td' + name).style.color = '#6f6f6f';
    document.getElementById('menu' + name).style.visibility = 'hidden';
    document.getElementById('menu' + name + 'Shadow').style.visibility = 'hidden';
    document.getElementById('menu' + name + 'ShadowBottom').style.visibility = 'hidden';
    document.getElementById('menu' + name + 'ShadowBottomLeft').style.visibility = 'hidden';
    document.getElementById('menu' + name + 'ShadowRight').style.visibility = 'hidden';
    document.getElementById('menu' + name + 'ShadowBottomRight').style.visibility = 'hidden';
}

function hideMenus() {

    if (!inPartnersHdr && !inPartnersMenu) {
        hideMenu('Partners');
    }

    if (!inServicesHdr && !inServicesMenu) {
        hideMenu('Services');
    }

    if (!inCompanyHdr && !inCompanyMenu) {
        hideMenu('Company');
    }

    if (!inContactHdr && !inContactMenu) {
        hideMenu('Contact');
    }
}
function findPosX(obj) {
    var leftCoor;
    leftCoor = 0;
    while (obj != null) {
        leftCoor += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    return leftCoor;
}

function findPosY(obj) {
    var topCoor;
    topCoor = 0;
    while (obj != null) {
        topCoor += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return topCoor;
}

function moveElementRelative(id, idTo, offsetX, offsetY) {
    var curX, curY, e;
    e = document.getElementById(idTo);
    curX = findPosX(e);
    curY = findPosY(e);
    document.getElementById(id).style.visibility = 'hidden';
    document.getElementById(id).style.left = (curX + offsetX) + 'px';
    document.getElementById(id).style.top = (curY + offsetY) + 'px';
    document.getElementById(id).style.visibility = 'visible';
}
