/************************************************************************************************************
(C) www.accordian.com, November 2005

This is a script from www.accordian.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.accordian.com
Alf Magne Kalleland

************************************************************************************************************/

var accordian_slideSpeed = 50;	// Higher value = faster
var accordian_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var accordian_activeId = false;
var accordian_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(accordian_slideInProgress)return;
	accordian_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('accordian_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(accordian_activeId &&  accordian_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(accordian_activeId,(accordian_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,accordian_slideSpeed);
		}
	}else{
		slideContent(numericId,(accordian_slideSpeed*-1));
		accordian_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('accordian_a' + inputId);
	var contentObj = document.getElementById('accordian_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',accordian_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('accordian_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('accordian_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,accordian_slideSpeed);				
			}else{
				accordian_slideInProgress = false;
			}
		}else{
			accordian_activeId = inputId;
			accordian_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	var count = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='accordian_question'){
			count++;
			divs[no].onclick = showHideContent;
			divs[no].id = 'accordian_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'accordian_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='accordian_answer_content';
			contentDiv.id = 'accordian_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';

			divCounter++;
		}		
	}	
	showHideContent('','accordian_q1');
}
//window.onload = initShowHideDivs;
