function Accordion(accordion) {
	var oAccordion = $(accordion);
	oAccordion.Headers = [];
	oAccordion.Contents = [];
	oAccordion.MaxHeight = 0;

	if(!window['accordionmoving']) {
		window['accordionmoving'] = {hide : false, show : false};
	}
	var oMoving = window['accordionmoving'];
	
	this.show = function(obj, timeout) {
		if(obj.node.offsetHeight < obj.node.scrollHeight && obj.node.innerHTML != '') {
			obj.node.style.height = (obj.node.offsetHeight + ((obj.node.scrollHeight - obj.node.offsetHeight) * 0.1 < 1 ? 1 : (obj.node.scrollHeight - obj.node.offsetHeight) * 0.1)) + "px";
			window.setTimeout(bindFunction(function() {this.show(obj, timeout)}, this), timeout);
		} else {
			//obj.node.style.height = "auto";
			obj.opened = true;
			oMoving.show = false;
		}
	}
	
	this.hide = function(obj, timeout) {
		if(obj.node.offsetHeight > 0 && obj.node.innerHTML != '') {
			obj.node.style.height = (obj.node.offsetHeight - (obj.node.offsetHeight * 0.05 < 1 ? 1 : obj.node.offsetHeight * 0.1)) + "px";
			window.setTimeout(bindFunction(function() {this.hide(obj, timeout)}, this), timeout);
		} else {
			obj.opened = false;
			oMoving.hide = false;
		}
	}
	
	var oNodes = [];
	for(var i = 0; i < oAccordion.childNodes.length; i++) {
		if(oAccordion.childNodes[i].tagName != undefined && ["h1", "h2", "h3", "h4", "h5", "h6", "div"].inArray(oAccordion.childNodes[i].tagName.toLowerCase())) {
			oNodes.push(oAccordion.childNodes[i]);
		}
	}
	
	for(var i = 0; i < oNodes.length; i++) {
		if(["h1", "h2", "h3", "h4", "h5", "h6"].inArray(oNodes[i].tagName.toLowerCase())) {
			oAccordion.Headers.push({
				node : oNodes[i]
			});
			if(i + 1 < oNodes.length) {
				i++;
				if("div" == oNodes[i].tagName.toLowerCase()) {
					if(oNodes[i].scrollHeight > oAccordion.MaxHeight) {
						oAccordion.MaxHeight = oNodes[i].scrollHeight;
					}
					oAccordion.Contents.push({
						node : oNodes[i],
						header : oAccordion.Headers[oAccordion.Headers.length - 1],
						height : oNodes[i].scrollHeight,
						show : this.show,
						hide : this.hide,
						opened : false
					});
					
					oAccordion.Headers[oAccordion.Headers.length - 1].content = oAccordion.Contents[oAccordion.Contents.length - 1];
					oNodes[i].style.overflow = "hidden";
					if(oNodes[i].className != "opened") {
						oNodes[i].style.height = "0";
					} else {
						oAccordion.Contents[oAccordion.Contents.length - 1].opened = true;
					}
				}
			}
		}
	}
	

	for(var i = 0; i < oAccordion.Headers.length; i++) {
		oAccordion.Headers[i].node.onmouseover = bindFunction(function() {
			if(!oMoving.hide && !oMoving.show) {
				for(var j = 0; j < oAccordion.Contents.length; j++) {
					if(oAccordion.Contents[j].opened && oAccordion.Contents[j] != this.content) {
						oMoving.hide = true;
						window.setTimeout(bindFunction(function() {this.hide(this, 15)}, oAccordion.Contents[j]), 15);
					}
				}
				if(!this.content.opened) {
					oMoving.show = true;
					this.node.parentNode.style.height = "auto";
					window.setTimeout(bindFunction(function() {this.content.show(this.content, 15)}, this), 15);
				}
			}
		}, oAccordion.Headers[i]);
	}

}
