// 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, navn)
{
    // wait for another animated expand/collapse action to end
    if (currentContent===null)
    {
        currentContent = content;
        
		while (currentContent.nodeType !=1)
		{
			currentContent = currentContent.nextSibling;
		}        
        
        var expand = (currentContent.style.display=="none");
        if (expand){
            currentContent.style.display = "block";
            }
        var max_height = currentContent.offsetHeight;

        var step_height = step + (expand ? 0 : -max_height);
        toggleChevronIcon(currentContent);
    	
    	setCookie(navn,expand,365);
    	
        // schedule first animated collapse/expand event
        currentContent.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))
    {
        var new_step_height = step_height+step;
        currentContent.style.height = Math.abs(new_step_height) + "px";
        setTimeout("togglePannelAnimatingStatus(" + interval + "," + step + "," + max_height + "," + new_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 = document.getElementById('ShowHide');//content.parentNode.firstChild.childNodes[1].childNodes[0].childNodes[0].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(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
}

