function transform(oldBox, newBox, steps, speed){
	newBox.setStyle({
			position: 'absolute',
			left: oldBox.cumulativeOffset()[0] + 'px',
			top: oldBox.cumulativeOffset()[1] + 'px'
		});
	newBox.setOpacity(0.1);
	newBox.show();

	var orgNewWidth = newBox.getWidth();
	var orgNewHeight = newBox.getHeight();

	var stepW = (newBox.getWidth() - oldBox.getWidth()) / 10;
	var stepH = (newBox.getHeight() - oldBox.getHeight()) / 10;
	var stepO = 100 / steps;

	oldBox.setStyle({overflow: 'hidden'});
	newBox.setStyle({
			zIndex: 5000,
			overflow: 'hidden',
			width: oldBox.getWidth() + 'px',
			height: oldBox.getHeight() + 'px'
		});

	function fade(op){
		var w = Math.round(oldBox.getWidth() + stepW);
		var h = Math.round(oldBox.getHeight() + stepH);

		if (stepW >= 0 && w > orgNewWidth || stepW < 0 && w < orgNewWidth) w = orgNewWidth;
		if (stepH >= 0 && h > orgNewHeight || stepH < 0 && h < orgNewHeight) h = orgNewHeight;

		op += stepO;
		if (op >= 100) op = 100;
		oldBox.setOpacity((100 - op) / 100);
		newBox.setOpacity(op / 100);

		style = { width: w + 'px', height: h + 'px'};
		oldBox.setStyle(style);
		newBox.setStyle(style);

		if (op < 100) {
			fade.delay(speed / 1000, op);
		} else {
			oldBox.update(newBox.innerHTML);
			oldBox.setStyle({overflow: 'visible'});
			oldBox.setOpacity(1);
			newBox.remove();
		}
	}

	fade(0);
}

var fx_enabled = true;
var fx_speed = 10;
var fx_step = 20;
var fx_limit = 200;

function fx_show(div, recall, h, step){
	if (div.readAttribute('fxfade') == 'out') {
		return;
	}
	if (!fx_enabled) {
		div.show();
		return;
	}
	if (!h || !step) {
		if (div.visible()) {
			return;
		}
		div.show();
		h = div.getHeight();
		if (h / fx_step * fx_speed > fx_limit)
			step = Math.round(h / fx_limit * fx_speed);
		else step = fx_step;
		div.setStyle({overflow: 'hidden', height: '0px'});
		div.setOpacity(0);
		div.writeAttribute('fxfade', 'in');
		var newH = step;
	}
	else {
		var newH = div.getHeight() + step;
	}

	if (newH < h) {
		div.setStyle({'height': newH+'px'});
		div.setOpacity(newH / h);
		fx_show.delay(fx_speed / 1000, div, recall, h, step);
	}
	else {
		div.setStyle({height:'',overflow:''});
		div.setOpacity(1);
		div.writeAttribute('fxfade', null);
		if (typeof recall == 'function') {
			recall();
		}
	}
	//div.scrollIntoView(true);
}

function fx_hide(div, recall, h, step){
	if (!div.visible() || div.readAttribute('fxfade') == 'in') {
		return;
	}
	if (!fx_enabled) {
		div.hide();
		return;
	}
	if (!h || !step) {
		h = div.getHeight();
		if (h / fx_step * fx_speed > fx_limit)
			step = Math.round(h / fx_limit * fx_speed);
		else step = fx_step;

		div.setStyle({height: h+'px',overflow:'hidden'});
		div.writeAttribute('fxfade', 'out');
	}

	newH = div.getHeight() - step;

	if (newH > 0) {
		div.setStyle({'height':newH+'px'});
		div.setOpacity(newH / h);
		fx_hide.delay(fx_speed / 1000, div, recall, h, step);
	}
	else {
		div.setStyle({height:'',overflow:''});
		div.hide();
		div.writeAttribute('fxfade', null);
		if (typeof recall == 'function') {
			recall();
		}
	}
}

function fx_toggle(div, recall){
	if (div.visible()) {
		fx_hide(div, recall);
	} else {
		fx_show(div, recall);
	}
}