﻿// 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 togglePannelAnimatedStatus(content, interval, step, id)
{
    // wait for another animated expand/collapse action to end
    if (currentContent==null)
    {
        currentContent = content;
        var expand = (content.style.display=="none");
        if (expand){
            content.style.display = "block";
            //alert ( 'open:'+id );
            if(id){ setCookie( id, false ); }
        } else {
            //alert ( 'close:'+id );
            if(id){ setCookie( id, true ); }
        }
        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 + ")", interval);
    }
}

function togglePannelAnimatingStatus(interval, step, max_height, step_height)
{
    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 + ")", 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 setCookie( name, value ){
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	expires = 30 * 1000 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires) );
	
	var path = '/';
	var domain = '';
	var secure = '';
	
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// modified version for front page

// change chevron icon into either collapse or expand
function toggleMinMaxIcon(content)
{
    var chevron = content.parentNode.firstChild.childNodes[1].childNodes[0];
    var expand = (chevron.src.indexOf("min.gif")>0);
    chevron.src = chevron.src
        .split(expand ? "min.gif" : "max.gif")
        .join(expand ? "max.gif" : "min.gif");
}

function togglePannelAnimatedStatus2(content, interval, step, id)
{
    // wait for another animated expand/collapse action to end
    if (currentContent==null)
    {
        currentContent = content;
        var expand = (content.style.height == '30px');
        
        if(expand){
        	var start_h =  30;
        	var end_h   = 315;
	       	var inc_h   =  20;
	       	if(id){ setCookie( id, false ); }
        } else {
        	var start_h = 315;
        	var end_h   =  30;
        	var inc_h   = -20;
        	if(id){ setCookie( id, true ); }
        }
        
        toggleMinMaxIcon(content);
        setTimeout("richHack("+start_h+","+end_h+","+inc_h+")", 20);
    }
}

function richHack( current_h, end_h, inc_h ){
	if( inc_h > 0 ){
		if( current_h < end_h ){
			current_h += inc_h;
			currentContent.style.height = Math.abs(current_h) + "px";
			setTimeout("richHack("+current_h+","+end_h+","+inc_h+")", 20);
		} else {
			currentContent.style.height = Math.abs(end_h) + "px";
			currentContent = null;
		}
	} else {
		if( current_h > end_h ){
			current_h += inc_h;			
			currentContent.style.height = Math.abs(current_h) + "px";
			setTimeout("richHack("+current_h+","+end_h+","+inc_h+")", 20);
		} else {
			currentContent.style.height = Math.abs(end_h) + "px";
			currentContent = null;
		}
	}
}