/* renamed concertina to avoid confusion with accordion.js used elsewhere */
var defaultHeight = 100;
var timeToSlide = 250.0;
var openConcertina = '';

function initConcertina() {
	document.getElementById('ConcertinaContainer').style.display = "block";
}

function runConcertina(index, contentHeight) {
	if (!contentHeight) contentHeight = defaultHeight;
	var nID = "Concertina" + index + "Content";
	if (openConcertina == nID) nID = '';
	setTimeout("animate(" + new Date().getTime() + "," + timeToSlide + ",'" + openConcertina + "','" + nID + "','" + contentHeight + "')", 33);
	openConcertina = nID;
}

function animate(lastTick, timeLeft, closingId, openingId, contentHeight) {  
	var curTick = new Date().getTime();
	var elapsedTicks = curTick - lastTick;

	var opening = (openingId == '') ? null : document.getElementById(openingId);
	var closing = (closingId == '') ? null : document.getElementById(closingId);

	if (timeLeft <= elapsedTicks) {
		if (opening != null) opening.style.height = contentHeight + 'px';
		if (closing != null) {
		  closing.style.display = 'none';
		  closing.style.height = '0px';
		}
		return;
	}

	timeLeft -= elapsedTicks;
	var newClosedHeight = Math.round((timeLeft/timeToSlide) * contentHeight);

	if (opening != null) {
		if (opening.style.display != 'block') opening.style.display = 'block';
		opening.style.height = (contentHeight - newClosedHeight) + 'px';
	}

	if (closing != null) closing.style.height = newClosedHeight + 'px';

	setTimeout("animate(" + curTick + "," + timeLeft +",'" + closingId + "','" + openingId + "','" + contentHeight + "')", 33);
}

function limitChars(textarea, limit) {
	var text = textarea.value; 
	var textlength = text.length;
	if (textlength > limit) textarea.value = text.substring(0, limit);
}