var axWasLoaded;
var axCanCommunicate;
var axEstablished;
var axLastParam;
var axDocLocation;
var axIndexOfHash;
//var axStatus;
//var iFrameCount;
if (axWasLoaded != 1)
{
	axWasLoaded = 1;
	axEstablished = false;
	axCanCommunicate = true;
	axLastParam = "";
	axDocLocation = document.location.href;
	axIndexOfHash = axDocLocation.indexOf('#');
//	axStatus = new Array();
//	iFrameCount = 0;
	if(axIndexOfHash > 0)
		axDocLocation = axDocLocation.substring(0, axDocLocation.indexOf("#"));
}

function axInit(xiteplayerID, host)
{
//	iFrameCount++;
//	axStatus[axStatus.size] = new Array(2);
	var childUrl = "http://" + host + "/cgi-bin/xiteplayer.pl?id=" + xiteplayerID;

	setInterval(axCheckHash,100); 
	axSendUiMessage(childUrl, xiteplayerID);
}

function axExpandAll(){
	if (axCanCommunicate == false || axEstablished == true)
		return;
	var myIFrames = document.getElementsByTagName('iframe');
	for(var i = 0; i < myIFrames.length; i++)
		if (myIFrames[i].name.substring(0,7) == 'axchild'){
			myIFrames[i].width = 452;
			myIFrames[i].height = 311;
		}
}

function axCollapseAll() {
	if (axCanCommunicate == true || axEstablished == true)
		return;
	var myIFrames = document.getElementsByTagName('iframe');
	for(var i = 0; i < myIFrames.length; i++)
		if (myIFrames[i].name.substring(0,7) == 'axchild'){
			myIFrames[i].width = 344;
			myIFrames[i].height = 132;
		}
}

function axCheckHash() {
	var param = location.hash.substring(1);
	var dim, id, size;
	var widthSmall = "w304";
	var widthLarge = "w412";
	var heightSmall = "h92";
	var heightLarge = "h271";
	var idIndex = 0;
	
	
	if (param != axLastParam){ 
	

		axLastParam = param; 

		if(param == "noComm") {
			axCanCommunicate = false;
			axExpandAll();
			document.location = axDocLocation + "#axDoNothing";
		}

		else if(param == "canComm") {
			axCanCommunicate = true;
			axEstablished = true;
			axCollapseAll();
			document.location = axDocLocation + "#axDoNothing";
		}

		else{
			idIndex = param.indexOf('c');

			if(idIndex > 0 && (param.substring(0, idIndex) == widthSmall || param.substring(0, idIndex) == widthLarge || param.substring(0, idIndex) == heightSmall || param.substring(0, idIndex) == heightLarge)){
				
				dim = param.substring(0, 1);
				size = param.substring(1, idIndex);
				id = param.substring(idIndex + 1);
				
				changeSize(dim, size, id);

				document.location = axDocLocation + "#axDoNothing";
			}
		}
	}
}

function changeSize(dim, newSize, xiteplayerID){
	if (axCanCommunicate == false)
		return;
	var newValue = parseInt(newSize) + 40;
	if(dim == 'w')
		document.getElementById("axchild" + xiteplayerID).width = newValue;
	else
		document.getElementById("axchild" + xiteplayerID).height = newValue;
}				

function axSendUiMessage(childUrl, xiteplayerID) {
	/*fixes 404 problems with safari */
	var hashLocation = (document.location.href).indexOf('#');
	if(hashLocation > 0)
	  urlWithoutHash = (document.location.href).substring(0,hashLocation);
	else
	  urlWithoutHash = document.location.href;
	var url = childUrl + "#" + urlWithoutHash;
	document.getElementById("axchild" + xiteplayerID).src = url;
}
