// Initialize our global variables.
// var fadeValue = 0;
// var buttonCount = 0;

// This is the function that is called as soon as the page finishes loading.
function startUp(howManyButtons, roundingRadius)
{
	document.getElementById('redirectionBox').focus();
	// Initialize all the buttons
	for (j = 1; j<=howManyButtons; j++)
	{
		buttonInit(j, roundingRadius);
	}
	fadeEverythingIn(10);
}

function buttonInit(whichButton, roundingRadius)
{
	// Initialize some place holders.
	var zim = [];
	var ztb = 0;

	for (i = 0; i < 9; i++)
	{
		zim[i] = document.getElementById(('img' + whichButton) + i).style;
	}

	zoi = document.getElementById('overlay' + whichButton).style;
	ztb = document.getElementById('testBox' + whichButton);
	zsp = document.getElementById('splashPic');
	
	// Move the button to match the bottom of the splash image.
	ztb.style.top = (zsp.offsetTop + zsp.offsetHeight + (roundingRadius * 1.5) + 15) + "px";
	ztb.style.left = ((zsp.offsetLeft-75) + (((1 / 3) * whichButton) * (zsp.offsetWidth+150)) + (0 - (0.5 * ztb.offsetWidth))) + "px";
	
	// Align the sections with the text box.
	// -Corners-
	zim[0].left = (ztb.offsetLeft - roundingRadius) + "px";
	zim[0].top = (ztb.offsetTop - roundingRadius) + "px";
	zim[2].left = (ztb.offsetLeft + ztb.offsetWidth) + "px";
	zim[2].top = (ztb.offsetTop - roundingRadius) + "px";
	zim[6].left = (ztb.offsetLeft - roundingRadius) + "px";
	zim[6].top = (ztb.offsetTop + ztb.offsetHeight) + "px";
	zim[8].left = (ztb.offsetLeft + ztb.offsetWidth) + "px";
	zim[8].top = (ztb.offsetTop + ztb.offsetHeight) + "px";
	// -Sides-
	zim[1].left = (ztb.offsetLeft) + "px";
	zim[1].top = (ztb.offsetTop - roundingRadius) + "px";
	zim[1].width = (ztb.offsetWidth) + "px";
	zim[3].left = (ztb.offsetLeft - roundingRadius) + "px";
	zim[3].top = (ztb.offsetTop) + "px";
	zim[3].height = (ztb.offsetHeight) + "px";
	zim[5].left = (ztb.offsetLeft + ztb.offsetWidth) + "px";
	zim[5].top = (ztb.offsetTop) + "px";
	zim[5].height = (ztb.offsetHeight) + "px";
	zim[7].left = (ztb.offsetLeft) + "px";
	zim[7].top = (ztb.offsetTop + ztb.offsetHeight) + "px";
	zim[7].width = (ztb.offsetWidth) + "px";
	// -Center-
	zim[4].left = (ztb.offsetLeft ) + "px";
	zim[4].top = (ztb.offsetTop) + "px";
	zim[4].height = (ztb.offsetHeight) + "px";
	zim[4].width = (ztb.offsetWidth) + "px";
	// -Overlay-
	zoi.left = (ztb.offsetLeft) + "px";
	zoi.top = (ztb.offsetTop) + "px";
	zoi.width = (ztb.offsetWidth) + "px";
	zoi.height = (ztb.offsetHeight) + "px";
	
	// Make all the sections (and also the text box) visible
	for (x=0; x < 9; x++)
	{
		zim[x].visibility = 'visible';
	}
	zoi.visibility = 'visible';
	ztb.style.visibility = 'visible';
}

function fadeEverythingIn(fadeValue)
{
	//splashPic
	//splashBG
	//img{1 through 2}{0 through 8}
	//overlay{1 through 2}
	//testBox{1 through 2}
	//opacity:0.1;
	//filter:alpha(opacity=10);

	/*for (j = 1; j<=howManyButtons; j++)
	{
		buttonFade(j, fadeValue);
	}*/
	
	//setOpacity(document.getElementById('splashPic').style, fadeValue);
	//setOpacity(document.getElementById('splashBG').style, fadeValue);
	
	//document.getElementById('bod').style.background = "rgb(" + (fadeValue*10) + "%," + (fadeValue*10) + "%," + (fadeValue*10) + "%)"
	
	setOpacity(document.getElementById('generalOverlay').style, fadeValue);
	
	fadeValue -= 0.75;
	
	if (fadeValue >= 0)
	{
		setTimeout("fadeEverythingIn("+ fadeValue +")", 75);
	}
	else
	{
		document.getElementById('generalOverlay').style.display = 'none';
	}
		
}

function setOpacity(whichObject, value)
{
	whichObject.opacity = value/10;
	whichObject.filter = 'alpha(opacity=' + value*10 + ')';
}

/*function buttonFade(whichButton, fadeValue)
{
	for (i = 0; i < 9; i++)
	{
		setOpacity(document.getElementById(('img' + whichButton) + i).style, fadeValue);
	}

	setOpacity(document.getElementById('overlay' + whichButton).style, fadeValue);
	setOpacity(document.getElementById('testBox' + whichButton).style, fadeValue);
	
}*/

function checkForRedirection()
{
	tempV = document.getElementById('redirectionBox').value;
	if (tempV=='e' || tempV=='E')
	{	
		document.getElementById('redirectionBox').value = '';
		window.location = 'text-only.php'
	}
	else if (tempV=='f' || tempV=='F')
	{
		document.getElementById('redirectionBox').value = '';
		window.location = 'texte-seulement.php'
	}
	
	document.getElementById('redirectionBox').value = '';
}
