﻿// JScript File

var visibleMenu = null;
var showProc = false;
var scrollPos = 0;
var itemHeight = 22;
var scrollInterval = null

function RelocateFloatBox()
{
    var div = document.getElementById("divFloatBox");
    var con = document.getElementById("Container2");
    if(div != null && con != null)
    {
        div.style.width = con.offsetWidth;
        div.style.height = con.offsetHeight;
        div.style.left = GetPosX(con) + 9;
        div.style.top = GetPosY(con) + 13;
    }
}



function GetPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
	    while (obj.offsetParent)
	    {
		    curleft += obj.offsetLeft
		    obj = obj.offsetParent;
	    }
    }
    else if (obj.x)
    curleft += obj.x;
    return curleft;
}

function GetPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
	    while (obj.offsetParent)
	    {
		    curtop += obj.offsetTop
		    obj = obj.offsetParent;
	    }
    }
    else if (obj.y)
    curtop += obj.y;
    return curtop;
}

function ShowSubMenu()
{
    var ctrl = window.event.srcElement;
    if(ctrl == null) return;
    
    var menuName = ctrl.id
    var xPos = GetPosX(ctrl)-123;
    var yPos = GetPosY(ctrl)+15;
    var close = false;
    if(menuName.length == 0) return;
    
    if(visibleMenu == ctrl) close = true;
    HideSubMenu();
    if(close) return;
    
    visibleMenu = ctrl;
    
    var i = 1;
    var subMenu = document.getElementById(menuName + "_" + i);

    while(subMenu != null)
    {
        subMenu.style.top = yPos;
        subMenu.style.left = xPos ;
        subMenu.style.display = "block";
        subMenu = document.getElementById(menuName + "_" + ++i);
    }
    if(scrollInterval != null) window.clearInterval(scrollInterval);
    scrollInterval = window.setInterval(ScrollEffect, 30);
    showProc = true;
}

function ScrollEffect()
{
    if(visibleMenu == null) return;
    var menuName = visibleMenu.id
    if(scrollPos >= 5)
    {
        SetFinalPosition();
        window.clearInterval(scrollInterval);
        scrollPos = 0;
        showProc = false;
        return;
    }
    
    var i = 2;
    var subMenu = document.getElementById(menuName + "_2");
    if(subMenu == null) return;	        
    
    var point = document.getElementById(menuName + "_1")
    var topPos = point.style.top;
    topPos = topPos.substring(0, topPos.length - 2);
    topPos = parseInt(topPos);
    

    while(subMenu != null)
    {
        subMenu.style.top =      topPos + (4*(i-1)*(scrollPos+1));
        subMenu = document.getElementById(menuName + "_" + ++i);
    }
    scrollPos++;
}

function SetFinalPosition()
{
    if(visibleMenu == null) return;
    var menuName = visibleMenu.id
    var subMenu = document.getElementById(menuName + "_2");
    if(subMenu == null) return;	        

    var i = 2;
    var point = document.getElementById(menuName + "_1")
    var topPos = point.style.top;
    topPos = topPos.substring(0, topPos.length - 2);
    topPos = parseInt(topPos);

    while(subMenu != null)
    {
        subMenu.style.top =  topPos + (itemHeight * (i-1));
        subMenu = document.getElementById(menuName + "_" + ++i);
    }
}

function HideSubMenu()
{
    //alert(showProc)
    if(showProc) { showProc = false; return;}
    if(visibleMenu == null) return;
    
	var i = 1;
	var menuName = visibleMenu.id
	var subMenu = document.getElementById(menuName + "_" + i);
    
    while(subMenu != null)
    {
        subMenu.style.display = "none";
        subMenu = document.getElementById(menuName + "_" + ++i);
    }
    visibleMenu = null;
}

function MenuMouseEnter()
{
    var ctrl = window.event.srcElement;
    if(ctrl == null) return;
    
    ctrl.style.filter = "Alpha(Opacity=80)";
}

function MenuMouseLeave()
{
    var ctrl = window.event.srcElement;
    if(ctrl == null) return;
    
    ctrl.style.filter = "";
}

function DoNothing(){}
