﻿ //The addLoadEvent function is to load multiple functions when the document is opened.
 //It is supposed the browser getting confused with multiple requests at onLoad time.
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function swapImages()
{
   var waitTime = 4000;    
   
   // find number of quotes
   for (i=1; document.getElementById("banner" + i);i++)
   {
      document.getElementById("banner"+i).style.display = "none";
   }

   var total_images = --i;

   var iNo = total_images;       // current quote number 
   // All quotes except the first have display set to none to avoid sudden text change on open.
   // By setting the current quote number to the last one, the first one remains displayed for its allotted time.

   window.showImage = function()
   {

      document.getElementById("banner"+iNo).style.display = "none";
      iNo++;
      if (iNo > total_images)
         iNo = 1;

       document.getElementById("banner"+iNo).style.display = "block";

      showIt = setTimeout("showImage()", waitTime);
   }

   showImage();
}

function swapQuotes()
{
   var waitTime = 6000;    
   
   // find number of quotes
   for (i=1; document.getElementById("quote" + i);i++)
   {
      document.getElementById("quote"+i).style.display = "none";
   }

   var total_quotes = --i;

   var qNo = total_quotes;       // current quote number 
   // All quotes except the first have display set to none to avoid sudden text change on open.
   // By setting the current quote number to the last one, the first one remains displayed for its allotted time.

   window.showQuote = function()
   {

      document.getElementById("quote"+qNo).style.display = "none";
      qNo++;
      if (qNo > total_quotes)
         qNo = 1;

       document.getElementById("quote"+qNo).style.display = "block";

      showIt = setTimeout("showQuote()", waitTime);
   }

   showQuote();
}

addLoadEvent(swapImages);
addLoadEvent(swapQuotes);

