﻿// JavaScript Document

/************************************************************************************************************
(C) www.content.com, November 2005

This is a script from www.content.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.content.com
Alf Magne Kalleland

************************************************************************************************************/

var content_slideSpeed = 20;	// Higher value = faster
var content_timer = 20;	// Lower value = faster

var objectIdToSlideDown = false;
var content_activeId = false;
var content_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(content_slideInProgress)return;
	content_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('content_a' + numericId);
	
	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(content_activeId &&  content_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(content_activeId,(content_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,content_slideSpeed);
		}
	}else{
		slideContent(numericId,(content_slideSpeed*-1));
		content_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('content_a' + inputId);
	var contentObj = document.getElementById('content_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 + ')',content_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('content_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('content_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,content_slideSpeed);				
			}else{
				content_slideInProgress = false;
			}
		}else{
			content_activeId = inputId;
			content_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='content_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'content_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'content_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='content_answer_content';
			contentDiv.id = 'content_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}

//Added this to prevent jquery onload function from overriding it
if(typeof $j == 'undefined'){
	window.onload = initShowHideDivs;
}