function BlendInLayer(id,speed) 
{
    if (speed == 0) $("#" + String(id)).show(); else $("#" + String(id)).fadeIn(parseInt(speed));
}
function BlendOutLayer(id,speed) 
{
    if (speed == 0) $("#" + String(id)).heide; else $("#" + String(id)).fadeOut(parseInt(speed));
}
/*
function LoopContentNormal(loopContentArray, duration) 
{
    for(var lc = 0; lc<loopContentArray.length; lc++) 
    {
        var startoffset = already.length * (lc/duration);
        var parts = already[lc].split("_");
        if (parts[0] == "blend") setTimeout("blendContent"  + parts[1] + "()",startoffset);
        if (parts[0] == "loop") setTimeout("loopContent"  + parts[1] + "()",startoffset);
    }
}
*/
function LoopContentRandom(loopContentArray,duration) 
{
    //debugger;
    var cop = loopContentArray.slice(0, loopContentArray.length)
    var leng = cop.length;
    var already = new Array(leng);
    var c = 0;
    while (cop.length > 0) 
    {
        var ra = Math.random();
        var randomPos = Math.floor(ra * cop.length);
        already[c] = cop[randomPos];
        Array.removeAt(cop,randomPos);
        c++;
    }
    for(var lc = 0; lc<already.length; lc++) 
    {
        var startoffset = (duration / already.length) * lc;
        var parts = already[lc].split("_");
        if (parts[0] == "blend") setTimeout("blendContent"  + parts[1] + "()",startoffset);
        if (parts[0] == "loop") setTimeout("loopContent"  + parts[1] + "()",startoffset);
    }
    
}

function MakeAbsolutePosition(element) 
{
    document.body.appendChild(element);
}

function findTableHeaderNode(node) 
{
    if (node && node.tagName && node.tagName.toLowerCase() == "th") return node;
    for (var cc=0;cc<node.childNodes.length;cc++) 
    {
        var anode = findTableHeaderNode(node.childNodes[cc]);
        if (anode && anode.tagName && anode.tagName.toLowerCase() == "th") return anode;
    }
    return null;
}

function getMaxPanelContentHeight(panel) 
{
    var maxHeight = 0;
    for (var cc=0;cc<panel.childNodes.length;cc++) 
    {
        var itemHeight = panel.childNodes[cc].offsetTop + panel.childNodes[cc].offsetHeight;
        if (itemHeight > maxHeight) maxHeight = itemHeight;
    }
    return maxHeight;
}

function expandBatPanel(panelId, collapsedHeight) 
{
    var panel = document.getElementById(panelId);
    if (!collapsedHeight) 
    {
        var node = findTableHeaderNode(panel);
        if (node) collapsedHeight = node.offsetHeight;
        else collpasedHeight = 20;
    }
    if (panel)
    {
        var height = panel.offsetHeight;
        if (height == collapsedHeight) 
        {
            panel.style.overflow = "visible";
            panel.style.height = (getMaxPanelContentHeight(panel)+1) + "px";
        } 
        else 
        {
            panel.style.overflow = "hidden";
            panel.style.height = collapsedHeight + "px";
        }
    }   
}


