/************************************************************************************************************
(C) www.treatments.com, November 2005

This is a script from www.treatments.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.treatments.com
Alf Magne Kalleland

************************************************************************************************************/

var treatments_slideSpeed = 10;	// Higher value = faster
var treatments_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var treatments_cctiveId = false;
var treatments_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(treatments_slideInProgress)return;
	treatments_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var copyDiv = document.getElementById('treatments_c' + numericId);

	objectIdToSlideDown = false;
	
	if(!copyDiv.style.display || copyDiv.style.display=='none'){		
		if(treatments_cctiveId &&  treatments_cctiveId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(treatments_cctiveId,(treatments_slideSpeed*-1));
		}else{
			
			copyDiv.style.display='block';
			copyDiv.style.visibility = 'visible';
			
			slideContent(numericId,treatments_slideSpeed);
		}
	}else{
		slideContent(numericId,(treatments_slideSpeed*-1));
		treatments_cctiveId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('treatments_c' + inputId);
	var contentObj = document.getElementById('treatments_cc' + 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 + ')',treatments_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('treatments_c' + objectIdToSlideDown).style.display='block';
				document.getElementById('treatments_c' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,treatments_slideSpeed);				
			}else{
				treatments_slideInProgress = false;
			}
		}else{
			treatments_cctiveId = inputId;
			treatments_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='treatments_heading'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'treatments_h'+divCounter;
			var copy = divs[no].nextSibling;
			while(copy && copy.tagName!='DIV'){
				copy = copy.nextSibling;
			}
			copy.id = 'treatments_c'+divCounter;	
			contentDiv = copy.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='treatments_copy_content';
			contentDiv.id = 'treatments_cc' + divCounter;
			copy.style.display='none';
			copy.style.height='1px';
			divCounter++;
		}		
	}	
}
window.onload = initShowHideDivs;