function openCloseBox(elem, duration) {
	if (arguments.length == 1)
		duration = 'short';
	elem.set('tween', {duration: duration, property: 'height'});
	var myheight = elem.getComputedStyle('height').toInt();
	var mywidth = elem.getComputedStyle('width').toInt();
	elem.style.overflow = 'hidden';
	elem.opened = (myheight != 0);
	elem.targetHeight = function() {
		var oldWidth = this.getStyle('width');
		var oldHeight = this.style.height;
		this.setStyle('visibility', 'hidden');
		this.setStyle('position', 'absolute');
		this.setStyle('display', 'block');
		this.setStyle('height', 'auto');
		this.setStyle('width', mywidth);
		var h = this.offsetHeight;
		this.setStyle('width', oldWidth);
		this.setStyle('height', oldHeight);
		this.setStyle('position', null);
		this.setStyle('display', null);
		this.setStyle('visibility', null);
		return h;
	}
	elem.openBox = function() {
		this.tween(this.targetHeight());
		this.opened = true;
	}
	elem.closeBox = function() {
		this.tween('0px');
		this.opened = false;
	}
	elem.toggleBox = function() {
		if (this.opened) this.closeBox();
		else this.openBox();
	}
	elem.quickOpen = function() {
		this.setStyle('height', this.targetHeight()+'px');
		this.opened = true;
	}
	elem.quickClose = function() {
		this.setStyle('height', '0px');
		this.opened = false;
	}
}

document.addEvent('domready', function() {
	var elems = $$('.openclosebox');
	for(var i=0; i<elems.length; i++) {
		var elem = elems[i];
		openCloseBox(elem);
	}
});
