function Splash(sImage, sLink)
{
	// Swaps out splash image on home page

	var oObject = document.getElementById('Splash');
	if (!oObject)
		return;
	oObject.style.backgroundImage = 'url(images/' + sImage + ')';
	m_sDirectLink = sLink;

	var oTimerValue = document.getElementById('timerValue');
	if (!oTimerValue)
		return;
	if (sImage == 'splash1.gif')
		oTimerValue.style.visibility = 'visible';
	else
		oTimerValue.style.visibility = 'hidden';
}

function SetInnerText(oObject, sText)
{
	// Required because FireFox deletes notes when blank string is passed
	
	var sSetText = sText;
	if (sSetText == '')
		sSetText = '.';

	// Required because Firefox doesn't support innerText

	if (oObject.textContent)
		oObject.textContent = sSetText;
	else
		oObject.innerText = sSetText;
}

function padWith0(sSrc, iSize)
{
   var sWork = '' + sSrc;
   while (sWork.length < iSize)
      sWork = '' + '0' + sWork;
   return sWork;
}

function timerTick()
{
	setTimeout('timerTick()', 500);
	
	// Only update the timer if we're looking at the initial splash image
	
	var oSplash = window.document.getElementById('Splash');
	if (!oSplash) return;
	
	if (oSplash.style.backgroundImage.indexOf('splash1.gif') != -1)
	{
		var dCurrent = new Date();
		var iElapsedSecs = Math.floor((dCurrent - dStartedTiming) / 1000);
		var iTotalSecs = iRunningSecs + iElapsedSecs;
		
		// Format the new time
		
		sFormatted = FormatDuration(iTotalSecs, bAlternator, 6, ':');
		bAlternator = !bAlternator;

		// Swap them if they are different

		var oCell = window.document.getElementById('timerValue');
		if (!oCell) return;
		SetInnerText(oCell, sFormatted);
	}
}

function FormatDuration(iTotalSecs, bDisplaySeparator, iFormat, sSeparator)
{
   // Is it a null duration?

   if (iTotalSecs == 0)
      return '';

   // Calculate some helpful metrics

   var iHours = Math.floor(iTotalSecs / 3600);
   var iMins = Math.floor((iTotalSecs - (iHours * 3600)) / 60);
   var iSecs = Math.floor(iTotalSecs - (iHours * 3600) - (iMins * 60));
   var sSep = ' ';
   if (bDisplaySeparator)
      sSep = sSeparator;
   var sWork = '';

   if (iFormat == 1) // OUTPUT_S
   {
      sWork = '' + iTotalSecs
   }
   else if (iFormat == 2) // OUTPUT_MS
   {
      iMins = Math.floor((iTotalSecs - iSecs) / 60);
      sWork = '' + iMins;
      sWork += sSep;
      sWork += padWith0(iSecs, 2);
   }
   else if ((iFormat == 3) || (iFormat == 4) || (iFormat == 5)) // OUTPUT_HMS, OUTPUT_HM, OUTPUT_H
   {
      sWork = '' + iHours;
      if ((iFormat == 3) || (iFormat == 4))
      {
         sWork += sSep;
         sWork += padWith0(iMins, 2);
      }
      if (iFormat == 3)
      {
         sWork += sSep;
         sWork += padWith0(iSec, 2);
      }
   }
   if (iFormat == 6) // OUTPUT_HMSTRIM
   {
      if (iHours > 0)
      {
         sWork += iHours;
         sWork += sSep;
      }
      if ((iMins > 0) || (iHours > 0))
      {
         if (iHours > 0)
            sWork += padWith0(iMins, 2);
         else
            sWork += iMins;
      }
      sWork += sSep;
      sWork += padWith0(iSecs, 2);
   }
   if ((iFormat == 7) || (iFormat == 9)) // OUTPUT_HTENTHS, OUTPUT_HTENTHSH
   {
      sWork = '' + round(iTotalSecs / 3600, 1);
   }
   if ((iFormat == 8) || (iFormat == 10)) // OUTPUT_HHUNDREDTHS, OUTPUT_HHUNDREDTHSH
   {
      sWork = '' + round(iTotalSecs / 3600, 2);
   }
   return sWork;
}

function changeImages()
{
   if (document.images)
   {
      for (var i=0; i<changeImages.arguments.length; i+=2)
      {
         document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
      }
   }
}
