// <body onmousemove = "AnimateMenu(event);" onLoad="MenuGlobalList = new MenuList(); MenuGlobalList.RegisterMenu('divbody1', 'divhead1');  MenuGlobalList.RegisterMenu('divbody2', 'divhead2'); ">

function getElementPosition(elemId)
{
    var elem = document.getElementById(elemId);
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width":w, "height":h};
}


// для объектов
function MenuHead(id) 
{
    this.id = id;
    this.position = getElementPosition(this.id);
}

function MenuBody(id, idhead) 
{
    this.id = id;
    this.head = new MenuHead(idhead);
    this.IsDisplay = false;

    divobjbody = document.getElementById(this.id);
    divobjbody.style.position = 'absolute';
    divobjbody.style.left = this.head.position.left;
    divobjbody.style.top = this.head.position.top + this.head.position.height;
    divobjbody.style.width = this.head.position.width;
}

MenuBody.prototype.Show = function()
{
    if(!this.IsDisplay)
    {
        var divobjbody = document.getElementById(this.id);

        divobjbody.style.position = 'absolute';
        divobjbody.style.left = this.head.position.left;
        divobjbody.style.top = this.head.position.top + this.head.position.height;
        divobjbody.style.width = this.head.position.width;

        divobjbody.style.display = 'inline';

        this.position = getElementPosition(this.id);
        
        this.IsDisplay = true;
        // Редкое дополнение
        var tdcs = document.getElementById("tt" + this.head.id);
        tdcs.className = "areamag";
        
    }
}

MenuBody.prototype.Hide = function()
{
    if(this.IsDisplay)
    {
        var divobjbody = document.getElementById(this.id);

        divobjbody.style.position = 'absolute';
        divobjbody.style.left = this.head.position.left;
        divobjbody.style.top = this.head.position.top + this.head.position.height;
        divobjbody.style.width = this.head.position.width;

        divobjbody.style.display = 'none';
        
        this.IsDisplay = false;

        // Редкое дополнение
        var tdcs = document.getElementById("tt" + this.head.id);
        tdcs.className = "headblue2";
        
    }
}


function MenuList()
{
    this.MenuArray = new Array();
}

MenuList.prototype.RegisterMenu = function(id, idhead)
{
    var l = this.MenuArray.length;
    this.MenuArray[l] = new MenuBody(id, idhead);
}

var MenuGlobalList;


function IsOnSegment(param_point, param_min, param_max)
{
    return ((param_point >= param_min) && (param_point <= param_max));
}


function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
	return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}


function getCursorBodyPosition(evt)
{
    var e = (window.event) ? window.event : evt;
    x = e.clientX + getBodyScrollLeft();
    y = e.clientY + getBodyScrollTop();

    return {"x":x, "y":y};
}




function AnimateMenu(evt)
{
    var CursorPosition = getCursorBodyPosition(evt);
    if(MenuGlobalList)
    for(i = 0; i < MenuGlobalList.MenuArray.length; i++)
    {
        var mb = MenuGlobalList.MenuArray[i];
        mb.head.position = getElementPosition(mb.head.id);

        
        
        h = IsOnSegment(CursorPosition.x, mb.head.position.left, mb.head.position.left + mb.head.position.width);
        v = IsOnSegment(CursorPosition.y, mb.head.position.top, mb.head.position.top + mb.head.position.height);
        
        // Если навели на заголовок
        if(h && v)
        {
            mb.Show();
        }
        else
        {

            if(mb.IsDisplay)
            {
                h = IsOnSegment(CursorPosition.x, mb.position.left, mb.position.left + mb.position.width);
                v = IsOnSegment(CursorPosition.y, mb.position.top, mb.position.top + mb.position.height);
                if(h && v)
                {
                    //mb.Show();
                }
                else
                {
                    mb.Hide();
                }
                
            }
        }
    }
}



