// JavaScript Document

/**
 * Handles loading, sizing, and swaping images on the cover page.
 */
 var xHttpReq;
 var aPlayerImages	= new Array();
 var aCorpImages	= new Array();
 var nPlayerCounter = 0;
 var nCorpCounter = 0;
 var nImageTimer;
 var bSwapPlayer;


/**************************************************************************************************/


/**
 * Typical format of a multiline comment
 *
 *@param	Param1	Define Param1 here
 */
function getXML()
{
	var XMLHttp = null;
	if (window.XMLHttpRequest)
	{
		try
		{
			XMLHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			
		} // END TRY/CATCH
	}
	else if (window.ActiveXObject)
	{
		try
		{
			XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				XMLHttp = new ActiveXObject("Microsoft.XMLHHTP");
			}
			catch (e)
			{
				
			} // END TRY/CATCH
		} // END TRY/CATCH
	} // END IF
	return XMLHttp;
} // END FUNCTION getXML 


/**************************************************************************************************/


/**
 * Typical format of a multiline comment
 *
 *@param	Param1	Define Param1 here
 */
function importXML()
{
	//alert("importXML()");
	xHttpReq = getXML();
	xHttpReq.open("GET", "business/coverimages.php");
	xHttpReq.onreadystatechange = setImages;
	xHttpReq.send(null);
} // END FUNCTION importXML


/**************************************************************************************************/


/**
 * Typical format of a multiline comment
 *
 *@param	Param1	Define Param1 here
 */
function setImages()
{
	//alert("setImages()");
	if (xHttpReq.readyState == 4)
	{
		//alert(xHttpReq.responseXML);
		var xDataList = xHttpReq.responseXML;
		//alert(xDataList);
		var xData		= xDataList.getElementsByTagName("images")[0];
		//alert(xData);
		var nPlayerCount 	= 0;
		var nCorpCount		= 0;
		for (var firstNodeCount = 0; firstNodeCount < xData.childNodes.length; firstNodeCount++)
		{
			//alert(xData.childNodes[firstNodeCount].nodeName);
			if (xData.childNodes[firstNodeCount].nodeName == "player")
			{
				//alert("Player");
				var xPlayerNode = xData.childNodes[firstNodeCount];
				//alert(xPlayerNode.nodeName);
				for (var nPlayerNodeCount = 0; nPlayerNodeCount < xPlayerNode.childNodes.length; nPlayerNodeCount++)
				{
					if (xPlayerNode.childNodes[nPlayerNodeCount])
					{
						//alert(xPlayerNode.childNodes[nPlayerNodeCount]);
						//alert(xPlayerNode.childNodes[nPlayerNodeCount].nodeName);
						if (xPlayerNode.childNodes[nPlayerNodeCount].nodeName == "image")
						{
							var imgWidth = xPlayerNode.childNodes[nPlayerNodeCount].getAttribute("width");
							var imgHeight = xPlayerNode.childNodes[nPlayerNodeCount].getAttribute("height");
							aPlayerImages[nPlayerCounter] = new Image(imgWidth, imgHeight);
							aPlayerImages[nPlayerCounter].src = xPlayerNode.childNodes[nPlayerNodeCount].getAttribute("path");
							//alert(xPlayerNode.childNodes[nPlayerNodeCount].getAttribute("path"));
							nPlayerCounter++;
						} // END IF
					} // END IF
					
				} // END FOR
			} // END IF
			if (xData.childNodes[firstNodeCount].nodeName == "corp")
			{
				var xCorpNode = xData.childNodes[firstNodeCount];
				for (var nCorpNodeCount = 0; nCorpNodeCount < xCorpNode.childNodes.length; nCorpNodeCount++)
				{
					if (xCorpNode.childNodes[nCorpNodeCount])
					{
						if (xCorpNode.childNodes[nCorpNodeCount].nodeName == "image")
						{
							var imgWidth = xCorpNode.childNodes[nCorpNodeCount].getAttribute("width");
							var imgHeight = xCorpNode.childNodes[nCorpNodeCount].getAttribute("height");
							aCorpImages[nCorpCounter] = new Image(imgWidth, imgHeight);
							aCorpImages[nCorpCounter].src = xCorpNode.childNodes[nCorpNodeCount].getAttribute("path");
							nCorpCounter++;
						} // END IF
					} // END IF
					
				} // END FOR
			} // END IF
		} // END FOR
		nPlayerCounter = 0;
		nCorpCounter = 0;
		bSwapPlayer = false;
		nImageTimer = setInterval("onTimer()", 2000);
	} // END IF
} // END FUNCTION setImages


/**************************************************************************************************/


/**
 * Typical format of a multiline comment
 *
 *@param	Param1	Define Param1 here
 */
function onTimer()
{
	//alert(aPlayerImages[nPlayerCounter]);
	//alert("onTimer()");
	var divWidth 	= (bSwapPlayer)? document.getElementById('index-Personal').offsetWidth 	: document.getElementById('index-Commercial').offsetWidth;
	var divHeight 	= (bSwapPlayer)? document.getElementById('index-Personal').offsetHeight 	: document.getElementById('index-Commercial').offsetHeight;
	var imgWidth	= (bSwapPlayer)? aPlayerImages[nPlayerCounter].width	: aCorpImages[nCorpCounter].width;
	var imgHeight	= (bSwapPlayer)? aPlayerImages[nPlayerCounter].height	: aCorpImages[nCorpCounter].height;
	if (imgWidth > divWidth || imgHeight > divHeight)
	{
		var diffWidth 	= imgWidth - divWidth;
		var diffHeight 	= imgHeight - divHeight;
		if (diffWidth >= diffHeight)
		{
			imgWidth	= imgWidth - diffWidth;
			imgHeight	= imgHeight - diffWidth;
		}
		else
		{
			imgWidth	= imgWidth - diffHeight;
			imgHeight	= imgHeight - diffHeight;
		} // END IF
	} // END IF
	if (bSwapPlayer)
	{
		var sInnerHtml = "<a href=\"portfolio.php?port=player\">";
		sInnerHtml = sInnerHtml + "<img src=\""+aPlayerImages[nPlayerCounter].src+"\" width=\""+imgWidth+"\" height=\""+imgHeight+"\" border=\"0\" />\n";
		sInnerHtml = sInnerHtml + "</a>\n";
		document.getElementById('index-Personal').innerHTML = sInnerHtml;
		nPlayerCounter = (nPlayerCounter < aPlayerImages.length - 1)? nPlayerCounter + 1 : 0;
		//alert(document.getElementById('Personal').innerHTML);
	}
	else
	{
		var sInnerHtml = "<a href=\"portfolio.php?port=corporate\">";
		sInnerHtml = sInnerHtml + "<img src=\""+aCorpImages[nCorpCounter].src+"\" width=\""+imgWidth+"\" height=\""+imgHeight+"\" border=\"0\" />\n";
		sInnerHtml = sInnerHtml + "</a>\n";
		document.getElementById('index-Commercial').innerHTML = sInnerHtml;
		nCorpCounter = (nCorpCounter < aCorpImages.length - 1)? nCorpCounter + 1 : 0;
		//alert(document.getElementById('Commercial').innerHTML);
	} // END IF
	bSwapPlayer = !bSwapPlayer
} // END FUNCTION onTimer
