// Random Image Displayer 1.2
// javascript written By Paul McClain
// copyRight 2001 California State University


// Global Variables
 var Max = 23;
 var campusArray = new Array(Max);


// Builds the Array containing value n 
function buildArray()
 {
  for(i=0; i<Max; i++){
  campusArray[i] = "n";} 
 }

// Updates campus array when image is viewed value becomes y
function updateArray(imgSelected)
 {
  campusArray[imgSelected] = "y";
 }

// Checks to see if all images have been viewed, returns True:False
function isAllViewed()
 {
  var stillOpen = "true";
  for(i=0; i<Max; i++)
   {
    if(campusArray[i] == "n")
     stillOpen = "false";
   }
  return stillOpen;
 }

// Checks to see if Img has been viewed, returns True:False
function isViewed(imgSelected)
 {
  var Viewed = "false";
  if(campusArray[imgSelected] == "y")
   Viewed = "true";
   return Viewed;
 }

// Creates a random number and returns the number
function randomNumber() 
 {
  var randomNum;
  while (isNaN(randomNum))
   {
    randomNum = Math.round(Math.random()*22);
   }
  return randomNum;
 }

// Display campus Images randomly but not repetitively
function displayImage() 
 {
  var theImage = "/images/campuses/image";
  var theName = "/images/campus_titles/image";
  var theNum = randomNumber();

  if( isAllViewed() == "true" )
   {
    buildArray();
    displayImage();
   }
  else
  if( isViewed(theNum) == "true")
     displayImage();
  else
   {
    theImage += theNum + ".jpg";
    theName += theNum + ".gif";
    document.CampusImage.src = theImage;
    document.CampusName.src = theName;
    updateArray(theNum);
   }
 }

// Initially displays random image
function initImage()
 {
  buildArray();
  displayImage();
 }

// Print Array from 0 to Max
function printArray()
 {
  for(i=0; i<Max; i++)
   document.write(i + ' ' + campusArray[i] + '<br>');
 }