/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.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.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var iSlideSpeed = 30;	// higher value = faster
var iTimer = 10;		// lower value = faster

var objectIdToSlideDown = false;
var block_activeId = false;
var blnSlideInProgress = false;

function showHideContent(e,inputId)
{
	// zorgt ervoor dat 1 blok tegelijk geopend / gesloten kan worden
	//if(blnSlideInProgress) return;

	blnSlideInProgress = true;
	
	if(!inputId) inputId = this.id;
	
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var contentContainerDiv = document.getElementById('contentContainer' + numericId);

	objectIdToSlideDown = false;
	
	if(!contentContainerDiv.style.display || contentContainerDiv.style.display == 'none')
	{
		contentContainerDiv.style.display = 'block';
		contentContainerDiv.style.visibility = 'visible';
		
		slideContent(numericId,iSlideSpeed);

		// block was slided open
		return true;
	}
	else
	{
		slideContent(numericId,(iSlideSpeed *- 1));
		block_activeId = false;

		// block was slided close
		return false;
	}
}

function slideContent(inputId,direction)
{
	var obj = document.getElementById('contentContainer' + inputId);
	var contentObj = document.getElementById('slidingContainer' + inputId);

	height = obj.clientHeight;

	if(height == 0) height = obj.offsetHeight;

	height = height + direction;
	rerunFunction = true;

	if(height > contentObj.offsetHeight)
	{
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}

	// second condition is needed for IE, because IE doesn't support negative heights...
	if((height <= 1) || ((height + direction) <= 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 + ')', iTimer);
	}
	else
	{
		if(height <= 1)
		{
			obj.style.display='none';

			if(objectIdToSlideDown && objectIdToSlideDown != inputId)
			{
				document.getElementById('contentContainer' + objectIdToSlideDown).style.display = 'block';
				document.getElementById('contentContainer' + objectIdToSlideDown).style.visibility = 'visible';

				slideContent(objectIdToSlideDown,iSlideSpeed);
			}
			else
			{
				blnSlideInProgress = false;
			}
		}
		else
		{
			block_activeId = inputId;
			blnSlideInProgress = false;
		}
	}
}

function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	
	for(var no = 0; no < divs.length; no++)
	{
		if(divs[no].className == 'block_header')
		{
			var contentBlock = divs[no].nextSibling;

			while(contentBlock && contentBlock.tagName != 'DIV')
			{
				contentBlock = contentBlock.nextSibling;
			}

			slidingDiv = contentBlock.getElementsByTagName('DIV')[0];
			slidingDiv.style.top = 0 - slidingDiv.offsetHeight + 'px';

			contentBlock.style.height = '1px';
		}
	}
}