// JavaScript Document

window.onload = CollapseAnswers;

function CollapseAnswers()
{

    var answers = $$( ".answer" );
    answers.each
    ( 
        function(item)
        { 
            item.setAttribute( "displayHeight", item.offsetHeight );
            item.style.display = "none"; 
            item.style.overflow = "hidden";
            item.style.height = "0px"; 
            item.style.position = "static";
            item.style.top = "";
        } 
    );
    
}

function InsertContent(tid, question) 
{
    if(document.getElementById(tid).style.display == "none") 
    {
        var answerElement = $(tid);
        var height = parseInt( answerElement.getAttribute( "displayHeight" ) ) - 20;
        
        //if( /MSIE/.test(navigator.userAgent) ) { height -= 20; }
        
        answerElement.style.display = "";
 
	    document.getElementById(question).className = "question_on";	
        AnimateToggle( question, tid, 0, height, true );
        
	    //document.getElementById(tid).style.display = "";
    }

    else 
    {
        var answerElement = $(tid);
        var startHeight = parseInt( answerElement.getAttribute( "displayHeight" ) );
        var endHeight = 0;
        
	    document.getElementById(question).className = "question";	
        AnimateToggle( question, tid, startHeight, endHeight, false );

	    //document.getElementById(tid).style.display = "none";
	    //document.getElementById(question).className = "question";		
	}
}

function InsertContentFeat(tid, question) {
if(document.getElementById(tid).style.display == "none") {
	document.getElementById(tid).style.display = "";
	document.getElementById(question).className = "questionFeat_on";	
	}
else {
	document.getElementById(tid).style.display = "none";
	document.getElementById(question).className = "questionFeat";		
	}
}

function popwindow(url, name, attributes) {
		newwindow=window.open(url,name,attributes);
		if (window.focus) 
		{
		    newwindow.focus();
		}
		
		return newwindow;
	}
	
	
function AnimateToggle( questionId, answerId, height, targetHeight, isIncrementing )
{

    var answerElement = $(answerId);
    
    if( isIncrementing && height >= targetHeight )
    {
        answerElement.style.height = targetHeight + "px"; 
        return;   
    }

    else if( !isIncrementing && height <= targetHeight )
    {
        answerElement.style.height = targetHeight + "px"; 
        answerElement.style.display = "none";
        return;   
    }

    answerElement.style.height = height + "px";
    
    if( isIncrementing )
    {
        height += 10;
    }
    
    else
    {
        height -= 10;
    }
    
    
    window.setTimeout( 'AnimateToggle("' + questionId + '","' + answerId + '",' + height + ',' + targetHeight + ',' + isIncrementing + ')', 10 );     
    
}
