﻿// File JScript
function ExpandGlWindowEx (expand)
{
    var parentId = GetAttribute (expand, "parentId");
    var state = document.getElementById(parentId + "_state");
    var ctrlToExpand = GetAttribute (expand, "ctrlname");

    ctrlToExpand = document.getElementById (ctrlToExpand);
    
    if (ctrlToExpand.style.visibility == "hidden")
    {
        expand.src = GetAttribute (expand, "urlCloseImage");
        SetStateValue (state, "expanded", "true");
        Open (ctrlToExpand);
    }
    else
    {
        Close (ctrlToExpand, state);
        
        SetStateValue (state, "expanded", "false");
            
        expand.src = GetAttribute (expand, "urlOpenImage");
    }
}

function Close (element, state)
{
    SetAttribute (element, "oldPositionExp", element.style.position, state);
    SetAttribute (element, "oldOverflow", element.style.overflow, state);
    SetAttribute (element, "oldHeight", element.style.height, state);
    SetAttribute (element, "oldOffsetHeight", element.offsetHeight, state);
 
    element.style.height = GetAttribute (element, "oldOffsetHeight");
    element.style.overflow = "hidden";
    
    var slice = GetAttribute (element, "slice");
    SetAttribute (element, "counter", slice, null);
    SetAttribute (element, "animationHeight", slice, null);

    AnimateClose (element.id);
}

function AnimateClose (elementId)
{
    var element = document.getElementById (elementId);
    var height = GetAttribute (element, "oldOffsetHeight") / GetAttribute (element, "slice");
    var counter = GetAttribute (element, "counter");
    
    element.style.height = (height * counter) + 'px';
    SetAttribute (element, "counter", --counter, null);
    
    if (counter > 0)
        t = setTimeout ("AnimateClose('" + element.id + "')", 50);
    else
    {
        clearTimeout (t);
        element.style.position = "absolute";
        element.style.visibility = "hidden";
    }
} 

function Open (element)
{
    element.style.position = GetAttribute (element, "oldPositionExp");
    
    element.style.height = 0;
    element.style.visibility = "visible";
    element.style.overflow = "hidden";
    counter = 1;
    
    AnimateOpen (element.id);
}

function AnimateOpen (elementId)
{
    var element = document.getElementById (elementId);
    var height = GetAttribute (element, "oldOffsetHeight") / GetAttribute (element, "slice");
    var counter = GetAttribute (element, "counter");

    element.style.height = (height * counter) + 'px';
    SetAttribute (element, "counter", ++counter);
    if (counter <= 5)
        t = setTimeout ("AnimateOpen('" + elementId + "')", 50);
    else
    {
        clearTimeout (t);
        element.style.height = GetAttribute (element, "oldHeight");
        element.style.overflow = GetAttribute (element, "oldOverflow");
    }
}
