﻿// not animated collapse/expand
function togglePannelStatus(content)
{
    var expand = (content.style.display=="none");
    content.style.display = (expand ? "block" : "none");
    // toggleChevronIcon(content);
}

// current animated collapsible panel content
var currentContent = null;

function togglePannel_Collaps(Content, interval, step)
{
    var content = document.getElementById(Content);
        
    if(content == document.getElementById('CLPBLPNL_T_NEWS'))
    {
        if(document.getElementById('CLPBLPNL_T_NEWS').style.display == "block")
            IsBlock('CLPBLPNL_T_NEWS');
        if(document.getElementById('CLPBLPNL_T_EVENTS').style.display == "block")
            IsBlock('CLPBLPNL_T_EVENTS');
        if(document.getElementById('CLPBLPNL_T_THEATRE').style.display == "block")
            IsBlock('CLPBLPNL_T_THEATRE');
        if(document.getElementById('CLPBLPNL_T_ATT').style.display == "block")
            IsBlock('CLPBLPNL_T_ATT');
    }
    if(content == document.getElementById('CLPBLPNL_T_EVENTS'))
    {
        if(document.getElementById('CLPBLPNL_T_NEWS').style.display == "block")
            IsBlock('CLPBLPNL_T_NEWS');
        if(document.getElementById('CLPBLPNL_T_EVENTS').style.display == "block")
            IsBlock('CLPBLPNL_T_EVENTS');
        if(document.getElementById('CLPBLPNL_T_THEATRE').style.display == "block")
            IsBlock('CLPBLPNL_T_THEATRE');
        if(document.getElementById('CLPBLPNL_T_ATT').style.display == "block")
            IsBlock('CLPBLPNL_T_ATT');
    }
    if(content == document.getElementById('CLPBLPNL_T_THEATRE'))
    {
        if(document.getElementById('CLPBLPNL_T_NEWS').style.display == "block")
            IsBlock('CLPBLPNL_T_NEWS');
        if(document.getElementById('CLPBLPNL_T_EVENTS').style.display == "block")
            IsBlock('CLPBLPNL_T_EVENTS');
        if(document.getElementById('CLPBLPNL_T_THEATRE').style.display == "block")
            IsBlock('CLPBLPNL_T_THEATRE');
        if(document.getElementById('CLPBLPNL_T_ATT').style.display == "block")
            IsBlock('CLPBLPNL_T_ATT');
    }
    if(content == document.getElementById('CLPBLPNL_T_ATT'))
    {
        if(document.getElementById('CLPBLPNL_T_NEWS').style.display == "block")
            IsBlock('CLPBLPNL_T_NEWS');
        if(document.getElementById('CLPBLPNL_T_EVENTS').style.display == "block")
            IsBlock('CLPBLPNL_T_EVENTS');
        if(document.getElementById('CLPBLPNL_T_THEATRE').style.display == "block")
            IsBlock('CLPBLPNL_T_THEATRE');
        if(document.getElementById('CLPBLPNL_T_ATT').style.display == "block")
            IsBlock('CLPBLPNL_T_ATT');
    }
    //sleep(2000); 
    Expand(Content, interval, step);
            
}

function togglePannelAnimatedStatus(Content, interval, step)
{
    var content = document.getElementById(Content);
        
    // wait for another animated expand/collapse action to end
    content = document.getElementById(Content);
           
    if (currentContent==null)
    {
        currentContent = content;
        var expand = (content.style.display == "none");
                
        if (expand)
            content.style.display = "block";
            var max_height = content.offsetHeight;

            var step_height = step + (expand ? 0 : -max_height);
            //toggleChevronIcon(content);
                        
            // schedule first animated collapse/expand event
            content.style.height = Math.abs(step_height) + "px";
            setTimeout("togglePannelAnimatingStatus("
                + interval + "," + step
                + "," + max_height + "," + step_height +",'" + Content + "')", interval);
    }
   
}

function togglePannelAnimatingStatus(interval,step, max_height, step_height,Content)
{
    currentContent = document.getElementById(Content);
    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent.style.height = Math.abs(step_height) + "px";
            setTimeout("togglePannelAnimatingStatus("
            + interval + "," + step
            + "," + max_height + "," + step_height +",'" + Content + "')", interval);
    }
    // animated expand/collapse done
    else
    {
        if (step_height_abs<step)
            currentContent.style.display = "none";
        currentContent.style.height = "";
        currentContent = null;
    }
}

// change chevron icon into either collapse or expand
function toggleChevronIcon(content)
{
    var chevron = content.parentNode.firstChild.childNodes[1].childNodes[0];
    var expand = (chevron.src.indexOf("expand.gif")>0);
    chevron.src = chevron.src
        .split(expand ? "expand.gif" : "collapse.gif")
        .join(expand ? "collapse.gif" : "expand.gif");
}

function IsBlock(Content)
{
    var content = document.getElementById(Content);
    currentContent = content;
    var step = 5000;
    var interval = 0;
    var expand = (content.style.display == "none");
                
    var max_height = 50;

    var step_height = step + (expand ? 0 : -max_height);
    //toggleChevronIcon(content);
                        
    // schedule first animated collapse/expand event
//    content.style.height = Math.abs(step_height) + "px";
//    setTimeout("togglePannelAnimatingStatus("
//        + interval + "," + step
//        + "," + max_height + "," + step_height + ",'" + Content+ "')", interval);
content.style.display = "none";
                   
}
function Expand(Content, interval, step)
{
    //sleep(2000); 
    var content = document.getElementById(Content);
        
    // wait for another animated expand/collapse action to end
               
    if (currentContent!=null && currentContent.style.display != "none")
    {
        currentContent = content;
        var expand = (content.style.display == "none");
                
        if (expand)
            content.style.display = "block";
        var max_height = content.offsetHeight;

        var step_height = step + (expand ? 0 : -max_height);
        //toggleChevronIcon(content);
                        
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus("
            + interval + "," + step
            + "," + max_height + "," + step_height +",'" + Content + "')", interval);
        
       // document.write('Passed-1');
    }
    else
    {
        currentContent = content;
        var expand = (content.style.display == "none");
                
        if (expand)
            content.style.display = "block";
            var max_height = content.offsetHeight;

            var step_height = step + (expand ? 0 : -max_height);
            //toggleChevronIcon(content);
                        
            // schedule first animated collapse/expand event
            content.style.height = Math.abs(step_height) + "px";
            setTimeout("togglePannelAnimatingStatus("
                + interval + "," + step
                + "," + max_height + "," + step_height +",'" + Content + "')", interval);
    }
    //document.write('Passed-2');
} 
function sleep(milliseconds)
{
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) 
    {
        if ((new Date().getTime() - start) > milliseconds)
        {
            break;
        }
    }
}

