var fadeOut;
var fadeIn;
var URI; // original API path

function builderCall (url) {
	x = window.xajax;
	URI = x.config.requestURI;
	x.config.requestURI = url;

	// maybe a previous click is still active
	if ('undefined' != typeof fadeIn) {
		clearInterval (fadeIn);
	}
	if ('undefined' != typeof fadeOut) {
		clearInterval (fadeOut);
	}

	fadeOut = setInterval (builder_fadeOut, 50);


}

function builder_fadeOut () {
	content = document.getElementById('sisu_is');
	opacity = Number (content.style.opacity);
	if ('undefined' == typeof opacity || !opacity) { opacity = 1; }
	opacity = opacity = opacity - 0.1;
	
	if (opacity > 0) {
		content.style.opacity = opacity;
		content.style.filter = 'alpha(opacity=' + opacity * 100 + ')';
	} else {
		content.style.opacity = 0;
		content.style.filter = 'alpha(opacity=0)';
		clearInterval (fadeOut);
		
		// the current text has faded out, assign new text
		xajax.call ('builder', { parameters: [], mode: 'synchronous'} );
		window.xajax.config.requestURI = URI;

		// start fading back in
		fadeIn = setInterval (builder_fadeIn, 50);
	}
}

function builder_fadeIn () {
	content = document.getElementById('sisu_is');
	opacity = Number (content.style.opacity);
	if ('undefined' == typeof opacity) { opacity = 0; }

	if (opacity < 1) {
		opacity = opacity + 0.1;
		content.style.opacity = opacity;
		content.style.filter = 'alpha(opacity=' + opacity * 100 + ')';
	} else {
		clearInterval (fadeIn);
	}
}
