/////////////////////////////
//Jens's PR text randomizer//
/////////////////////////////
var aDivID = new Array();		//Array to store <div> elements in for displaying the PR blobs
var aPRText = new Array();		//Array storing PR blobs, the function FillPRText contains the PR blobs		
FillPRText();
var iDIV = 0;					//What <div> to use
var iDIVSave = 0;				//What <div> that was last used
var iBlobLength = 0;			//Stores the length of a PR Blob to decide display time of it

/*Configurables
 */
var fFadeIn = 0.0;				//Fade in from this value, anything above will not make the PR Blobs go away 
var fFadeOut = 0.7;				//Fade out from this value, 1.0 makes the PR Blob display with full opacity
var iFadeSpeed = 50;			//How long time between each 0.1 step in opacity fade, millisec


/*PR Blobs to use on page
 */
function FillPRText()
{	
	//<div> elements to use for display of PR blobs
	if(aDivID.length <= 0) {
		aDivID[0] = 'prText1';
		aDivID[1] = 'prText2';
		aDivID[2] = 'prText3';
		aDivID[3] = 'prText4';
	}
	
	//PR Blobs
	aPRText[0] = '<p>"Black Plague actually made me scream aloud in fright at one point."</p> <p class="prSign">PC Gamer - 83%</p>';
	aPRText[1] = '<p>"Black Plague combines puzzles and horror to create a game that is probably unlike anything you&#39;ve played."</p> <p class="prSign">1UP.com - 85%</p>';
	aPRText[2] = '<p>"At times the tension was more than I could bear."</p> <p class="prSign">The New York Times - 83%</p>';
	aPRText[3] = '<p>"With everything so rooted in reality, it&#39;s easy to lose your sense of place and feel like you&#39;re really stuck deep underground."</p> <p  class="prSign">Gamespot.com - 80%</p>';
	aPRText[4] = '<p>"This is an incredible game."</p> <p class="prSign">Gamernode.com - 95%</p>';
	aPRText[5] = '<p>"If you&#39;re in the market for a bite-sized chunk of the freshest horror adventure in years, play this game."</p> <p  class="prSign">AdventureGamers.com - 80%</p>';
	aPRText[6] = '<p>"It alternately shocks and entertains without resorting to the boring, repetitive combat we usually associate with survival horror."</p> <p  class="prSign">Destructoid.com - 80%</p>';
	aPRText[7] = '<p>"...be prepared for an engaging ride through a Lovecraftian gauntlet of horrors, enjoyable puzzles, eerie ambient tracks, and an immersive, disquieting atmosphere."</p> <p class="prSign">IGN.com - 77%</p>';
}

/*Select a random PR text
 */
function ChangePR()
{	
	//Make sure <div> used is not the same twice in a row
	do iDIV = Math.floor(Math.random()*aDivID.length);	
	while(iDIV == iDIVSave);
	
	iDIVSave = iDIV;
	
	//If the array of PR blobs is empty, refill it
	if(aPRText.length <= 0) FillPRText();	
	
	FadeIn();
}

/*Fade in the PR text
 */
var fMaxOpacity = fFadeOut;
function FadeIn()
{
	//On first step in fade calulate length to display PR blob, input PR blob to the <div> and remove it from the array.
	if(fFadeIn <= 0.0) {
		iBlobLength = aPRText[0].length*32;
		document.getElementById(aDivID[iDIV]).innerHTML = aPRText.shift();
	}
	
	//If fully faded, stay display on screen depending on length of PR Blob, then fade and display a new PR Blob.
	if(fFadeIn >= fMaxOpacity) {
		fFadeIn = fMinOpacity; 
		setTimeout('FadeOut()',iBlobLength);
		setTimeout('ChangePR()',iBlobLength+(iFadeSpeed*12));
		return;
	}

	/*For each loop increase opacity
	 */
	fFadeIn += 0.1;
	
	document.getElementById(aDivID[iDIV]).style.opacity = fFadeIn;
	document.getElementById(aDivID[iDIV]).style.filter = "alpha(opacity=" + fFadeIn*100 + ")";
	
	setTimeout('FadeIn()',iFadeSpeed);
}

/*Fadeout the PR text
 */
var fMinOpacity = fFadeIn;
function FadeOut()
{
	//If opacity 0, stop the fade out
	if(fFadeOut <= fMinOpacity){
		fFadeOut = fMaxOpacity; 
		return;
	}

	/*For each loop decrease opacity
	 */
	fFadeOut -= 0.1;
	
	document.getElementById(aDivID[iDIV]).style.opacity = fFadeOut;
	document.getElementById(aDivID[iDIV]).style.filter = "alpha(opacity=" + fFadeOut*100 + ")";
	
	setTimeout('FadeOut()',iFadeSpeed);
}