// Show-Hide Slider //

var contactslideSpeed = 10;	// Higher value = faster
var contacttimer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var contactactiveId = false;
var contactslideInProgress = false;
function showHideContent(e,inputId)
{
	if(contactslideInProgress)return;
	contactslideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var ContainerDiv = document.getElementById('contacta' + numericId);

	objectIdToSlideDown = false;
	
	if(!ContainerDiv.style.display || ContainerDiv.style.display=='none'){		
		if(contactactiveId &&  contactactiveId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(contactactiveId,(contactslideSpeed*-1));
		}else{
			
			ContainerDiv.style.display='block';
			ContainerDiv.style.visibility = 'visible';
			
			slideContent(numericId,contactslideSpeed);
		}
	}else{
		slideContent(numericId,(contactslideSpeed*-1));
		contactactiveId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('contacta' + inputId);
	var ContentObj = document.getElementById('contactac' + 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 + ')',contacttimer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('contacta' + objectIdToSlideDown).style.display='block';
				document.getElementById('contacta' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,contactslideSpeed);				
			}else{
				contactslideInProgress = false;
			}
		}else{
			contactactiveId = inputId;
			contactslideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='contactHeader'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'contactq'+divCounter;
			var Container = divs[no].nextSibling;
			while(Container && Container.tagName!='DIV'){
				Container = Container.nextSibling;
			}
			Container.id = 'contacta'+divCounter;	
			ContentDiv = Container.getElementsByTagName('DIV')[0];
			ContentDiv.style.top = 0 - ContentDiv.offsetHeight + 'px'; 	
			ContentDiv.className='contactContent';
			ContentDiv.id = 'contactac' + divCounter;
			Container.style.display='none';
			Container.style.height='1px';
			divCounter++;
		}		
	}	
}
window.onload = initShowHideDivs;