/*****************************************************************************
 * Filename: main.js                                                         *
 * Language: Javascript                                                      *
 * Purpose:  Provide functions for fading text in and out as well as changing*
 *           the text inside the box between each fade.                      *
 *                                                                           *
 ****************************************************************************/

//Global Variables
var hex=255, hex2=255; //initial color variable
var oldR1=99, oldR2=98, oldR3=97, oldR4=96, oldR5=95; //oldRandom values
var oldT=99;
var List = new Array(99), onceThrough=0, popList=0, lCount=0;
var ran=0;

function uniqueID()
{
    var newDate = new Date;
    return newDate.getTime();    
}

function roll_over(img_name, img_src)
{
    document[img_name].src = img_src;
}


function fadeIn(divName)
{ 
	if(hex>0) 
	{ //If color is not black yet
		hex-=10; // increase color darkness
		document.getElementById(divName).style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadeIn('" + divName + "')", 100); // continue fading in, # miliseconds between each shade
	}
	else
		setTimeout("fadeOut('" + divName + "')", 400); //fade out, # miliseconds before fading out
}

function fadeOut(divName) //Function to fade text from black to white (fade out)
{ 
	if(hex<255) 
	{ //If color is not white yet
		hex+=10; // increase color brightness
		document.getElementById(divName).style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadeOut('" + divName + "')", 12); 
	}
	else
	{
		setTimeout("changeText('" + divName + "')", 100);//change Text, # miliseconds before changing text
	}
}


function changeText(divName)
{
	var newContent;
	var TopLevel = 28;
	/*
	if (popList==0)//If the array has not yet been populated (just entered the site, first time through function)
	{
	   var rTemp;//create temp random variable
	   for( i=0; i < TopLevel; i++ )
	   {
	      var use=1; //use this value? by default yes
	      rTemp = Math.floor(Math.random() * TopLevel);//set rTemp to random value
	      for( n=0; n <= i; n++)//loop through the currently stored values
	      	if( List[n] == rTemp )//if that value is already stored
	      	   use=0;//do not use!
	      if( use == 1 )//if we should use that value
	         List[i] = rTemp;//add it to the list
	      else
	         i--;//retry a new random value for that index
	   }
	   
//        aList[0] = "Self-Awareness";
//        aList[1] = "Self-Understanding";
//        aList[2] = "Self-Actualization";
//        aList[3] = "Self-Consciousness";
//        aList[4] = "Self-Respect";

	   popList=1;//list has been populated
	}
	
	if( onceThrough == 0 )//if has not completed the first loop through the list
	{
	   ran = List[lCount++];//set next value = next on the array
	   if( lCount == TopLevel )//if on the last value
	   {
	   	onceThrough = 1;//set onceThrough to 1
	   	oldR1 = List[TopLevel-1];
	   	oldR2 = List[TopLevel-2];
	   	oldR3 = List[TopLevel-3];
	   	oldR4 = List[TopLevel-4];
	   	oldR5 = List[TopLevel-5];
	   }
	}
	
	else //if onceThrough is not 0 (already completed the unique pass through the list)
	{
   	   do //pull a number at random, ensuring it is not one of the last 5 displayed
	   {
	      ran = Math.floor(Math.random() * TopLevel);
	   }
	   
	   while(ran == oldR1 || ran == oldR2 || ran == oldR3 || ran == oldR4 || ran == oldR5);
	   // ^-Prevents the same content appearing within 5 rotations.
	   oldR5 = oldR4;
	   oldR4 = oldR3;
	   oldR3 = oldR2;
	   oldR2 = oldR1;
	   oldR1 = ran;
	}
*/
ran ++;

	switch(ran) //Select text based on random number (0-14)
	{
	   case 1:
	      newContent = "Alcohol Questionnaire";
	      break;
	   case 2:
	      newContent = "Loneliness Questionnaire";
	      break;
	   case 3:
	      newContent = "Alzheimer's Questionnaire";
	      break;
	   case 4:
	      newContent = "Stress Coping Abilities";
	      break;
	   case 5:
	      newContent = "Anger Questionnaire";
	      break;
	   case 6:
	      newContent = "Internet Addiction Questionnaire";
	      break;
	   case 7:
	      newContent = "Anxiety Questionnaire";
	      break;
	   case 8:
	      newContent = "Self-Esteem Questionnaire";
	      break;
	   case 9:
	      newContent = "Barriers To Employment";
	      break;
	   case 10:
	      newContent = "Substance Abuse Questionnaire";
	      break;
	   case 11:
	      newContent = "Depression Questionnaire";
	      break;
	   case 12:
	      newContent = "Loneliness Questionnaire";
	      break;	    
	   case 13:
	      newContent = "Distress Questionnaire";
	      break;	      
	   case 14:
	      newContent = "Drugs Questionnaire";
	      break;
	   case 15:
	      newContent = "Anger Questionnaire";
	      break;
	   case 16:
	      newContent = "Gambler Questionnaire";
	      break;
	   case 17:
	      newContent = "Alcohol Questionnaire";
	      break;
	   case 18:
	      newContent = "Internet Addiction Questionnaire";
	      break;
	   case 19:
	      newContent = "Depression Questionnaire";
	      break;
	   case 20:
	      newContent = "Post Traumatic Stress Questionnaire";
	      break;
	   case 21:
	      newContent = "Barriers To Employment";
	      break;
	   case 22:
	      newContent = "Self-Esteem Questionnaire";
	      break;
	   case 23:
	      newContent = "Gambler Questionnaire";
	      break;
	   case 24:
	      newContent = "Stress Coping Abilities";
	      break;
	   case 25:
	      newContent = "Distress Questionnaire";
	      break;	      
	   case 26:
	      newContent = "Internet Addiction Questionnaire";
	      break;
	   case 27:
	      newContent = "Substance Abuse Questionnaire";
	      break;
	   case 28:
	      newContent = "Drugs Questionnaire";
	      ran=0;
	      break;
	   default: //to catch 15 and anything above (should only be 0-14)
	      newContent = "OTHERS"
	      ran=0;
	      break;
	}
	
	document.getElementById(divName).innerHTML=newContent; //Set new content
	fadeIn(divName); //begin fade
}



	









