//*
//* student-profile-flip.js
//*
//* The javascript code to randomly flip the student profiles
//*
//* EFD - 10/4/2009
//*

//* some global parameters
var t; //* the timeout used to switch the profiles.
var iInterval = 15000; //* The timeout interval. defaulted to 15 seconds.
var iUpperBound = 1; //* The number of profiles

//* The class names of the profiles we will be flipping.
var sCurrentProfile;
var sNextProfile;

//*
//* showNext
//*
//* We need to setup the code to show the next profile
//* in a seperate function because it will get called
//* in a callback after the hide is finished.
//*
function showNext()
{
  jQuery(sNextProfile).show("slow");
}


//*
//* switchProfiles
//*
//* switch the profiles
//* 
function switchProfiles(iCurrentIndex)
{
 //* Make sure we select a different profile than the one that's currently selected.
 var iNextIndex = iCurrentIndex;
 while (iNextIndex == iCurrentIndex)
 {
  iNextIndex = Math.floor(Math.random() * iUpperBound ) + 1;
 }

 //* Now lets hide the current profile and display the next one.
 sCurrentProfile = ".student" + iCurrentIndex;
 sNextProfile = ".student" + iNextIndex;
 
 //* hide the current profile and use the callback to show the next one once the 
 //* hide is complete.
 jQuery(sCurrentProfile).hide("slow", showNext);



 //* restart the timer
 t = setTimeout( "switchProfiles(" + iNextIndex + ")", iInterval );
}

//*
//*   studentProfilesInit
//*
//* initilize the student profile flipping and display the first one.
//*
function studentProfilesInit( iCount )
{
  //* set the value of the upper bound
  iUpperBound = iCount;

  //* All the student profiles are hidden so now we need to select one 
  //* randomly and make if visible.
  var iRandNumber = Math.floor(Math.random() * iUpperBound ) + 1;
  var sSelectedProfile = ".student" + iRandNumber;

  jQuery(sSelectedProfile).show();

  //* Start the timer to rotate the profiles if we have more than 1
  if (iUpperBound > 1)
  {
    t = setTimeout( "switchProfiles(" + iRandNumber  + ")", iInterval);
  }
}