function Accordion() {
	this.onHeader = null;
	this.offHeader = null;
	this.onContent = null;
	this.offContent = null;
	this.incr = null;
	this.running = false;
	this.elements = new Array();
	this.id = Accordion.counter++;
	Accordion.instances.push(this);
}
Accordion.instances = new Array();
Accordion.counter = 0;
Accordion.prototype.add = function(header,content) {
	this.elements.push(header);
	header.content = content;
	header.container = this;
	header.onclick = function() {
		this.container.start(this);
	}
	header.onmouseover = function() {
		this.className += " hover";
	}
	header.onmouseout = function() {
		this.className = this.className.replace(/\bhover\b/,"");
	}
}
Accordion.prototype.start = function(header) {
	if(this.running || (this.onHeader && header == this.onHeader)) return;
	this.incr = 1;
	this.running = true;
	this.offHeader = this.onHeader ? this.onHeader : null;
	this.offContent = this.onContent ? this.onContent : null;
	this.onHeader = header;
	this.onContent = header.content;
	Accordion.run(this.id);
	this.onContent.className = "opening";
	this.timer = setInterval('Accordion.run(' + this.id + ')', 65);
}
Accordion.run = function(id) {
	var accordion = Accordion.instances[id];
	accordion.incr *= 3.5;
	var incr = accordion.incr;

	accordion.onContent.height = Math.min(accordion.onContent.height + incr, accordion.onContent.maxHeight);
	accordion.onContent.style.height = accordion.onContent.height + "px";

	accordion.offContent.height = Math.max(accordion.offContent.height - incr, 0);
	accordion.offContent.style.height = accordion.offContent.height + "px";
	
	if(accordion.onContent.height == accordion.onContent.maxHeight && accordion.offContent.height == 0) {
		clearInterval(accordion.timer);
		accordion.onHeader.className = "x";
		accordion.offHeader.className = "";
		accordion.offContent.className = "closed";
		accordion.running = false;
	}
}
Accordion.prototype.init = function(accordionHeight) { 
	var contentHeight = accordionHeight;
	
	for(var i=0; i < this.elements.length; i++) {
		contentHeight -= this.elements[i].offsetHeight;
	}
	
	var header = this.elements[0];
	var content = header.content;
	content.maxHeight = contentHeight;
	content.height = contentHeight;
	content.style.height = contentHeight + "px";
	this.onContent = content;
	this.onHeader = header;
	header.className = "x";

	for(var i=1; i < this.elements.length; i++) {
		var content = this.elements[i].content
		content.maxHeight = contentHeight;
		content.height = 0;
		content.className = "closed";
		content.style.height = 0;
	}

}
function accordionInit(accordionHeight) {
	var divs = document.getElementsByTagName("DIV");
	for(var i=0; i < divs.length; i++) {
		if(divs[i].className.search(/\baccordion\b/) == -1) continue;
		var accordion = new Accordion(i);
		var headers = divs[i].getElementsByTagName("H3");
		var contents = divs[i].getElementsByTagName("DIV");
		for(var j=0; j < headers.length; j++) {
			accordion.add(headers[j], contents[j]);
		}
		accordion.init(accordionHeight);
	}
}
