var current_open = null;

function accordion(id)
{	
	if(current_open != null && current_open.id == id)
	{
		closePage(current_open);
		current_open = null;
	}
	else
	{
		var element = document.getElementById(id);
		if(!element.currentHeight){ element.currentHeight = 0; }
		openPage(element,element.currentHeight);
		if (current_open != null)
			closePage(current_open);
		current_open = element;
	}
}

function openPage(element,start)
{
	window.clearInterval(element.animation);
	var step = 0;
	element.animation = window.setInterval(
		function(){
			element.currentHeight = doAnimation(start, element.scrollHeight, step, 50);
			element.style.height = element.currentHeight + "px";
			step++;
			if(step > 50){ window.clearInterval(element.animation); }
		}, 10);
}

function closePage(element)
{
	window.clearInterval(element.animation);
	var step = 0;
	element.animation = window.setInterval(
		function(){
			element.currentHeight = doAnimation(element.currentHeight, 0, step, 50);
			element.style.height = element.currentHeight + "px";
			step++;
			if(step > 50){ window.clearInterval(element.animation); }
		}, 10);
}

function doAnimation(start, end, steps, total)
{
	var change = end - start;
	var current = start + (((1/total)*steps) * change);
	return Math.round(current);
}