var ajaxResponseText;
var ajaxRequestIsInProgress = false;


function getExordium(url)
{
	if (ajaxRequestIsInProgress || !url)
	{
		return;
	}
	
	ajaxRequestIsInProgress = true;
	changeExordiumSwitcherState(0);
	
	try
	{
    	var ajaxSilentGet = new AJAXSilentGet(url);
		ajaxSilentGet.Get();
	}
	catch(ex)
	{
	}
}


function AJAXSilentGet(url)
{
	var xmlHttp = getXMLHTTPRequest();

	function getXMLHTTPRequest()
	{
		xmlHttp = false;

		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (ex1)
		{
			try
			{
		    	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		  	}
		  	catch (ex2)
		  	{
		    	xmlHttp = false;
		  	}
		}
		@end @*/
		
		if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
		{
			xmlHttp = new XMLHttpRequest();
		}
		
		return xmlHttp;
	}

	this.Get = function()
	{
		try
		{
			xmlHttp.open("GET", url, true);
			xmlHttp.onreadystatechange = function()
			{
				if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
				{
					try
					{
						ajaxResponseText = xmlHttp.responseText;
						var timer = setTimeout('fadeOut(0)', 1);
					}
					catch(ex2)
					{
					}
				}
			}
	  		xmlHttp.send(null);
		}
		catch(ex1)
		{
		}
	}	
}


function fadeOut(startColor)
{
	var timer;
	
	if (startColor == 252)
	{
		document.getElementById('exordiumContainer').innerHTML = ajaxResponseText;
		timer = setTimeout('fadeIn(' + startColor + ')', 1);
		return;
	}
	
	startColor += 6;
	
	document.getElementById('exordium').style.color = '#' + uByteToHex(170 + startColor / 3) + uByteToHex(startColor) + uByteToHex(startColor);
	timer = setTimeout('fadeOut(' + startColor + ')', 1);
}


function fadeIn(startColor)
{
	var timer;
	
	if (startColor == 0)
	{
		document.getElementById('newExordium').id = 'exordium';
		ajaxRequestIsInProgress = false;
		changeExordiumSwitcherState(1);
		return;
	}
	
	startColor -= 6;
	
	document.getElementById('newExordium').style.color = '#' + uByteToHex(170 + startColor / 3) + uByteToHex(startColor) + uByteToHex(startColor);
	timer = setTimeout('fadeIn(' + startColor + ')', 1);
}


function uByteToHex(byteValue)
{
	byteValue = parseInt(byteValue);

	if (isNaN(byteValue) || (byteValue < 0) || (byteValue > 255))
	{
		byteValue = 0;
	}
	
	var hexDigits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ];
	
	return hexDigits[parseInt(byteValue / 16)] + hexDigits[parseInt(byteValue % 16)];
}


function changeExordiumSwitcherState(state)
{
	state = parseInt(state);

	if (isNaN(state))
	{
		return;
	}
	
	switch (state)
	{
		case 0:
			document.getElementById('exordiumSwitcher').style.color = "#AAAAAA";
			document.getElementById('exordiumSwitcher').style.borderBottom = "1px dashed #AAAAAA";
			break;
			
		case 1:
			document.getElementById('exordiumSwitcher').style.color = "#AA0000";
			document.getElementById('exordiumSwitcher').style.borderBottom = "1px dashed #AA0000";
			break;

		default:
			break;
	}
}

