var StartVal = {value: -1};
var SeenIt = {value: "-"};
var NumSeen = {value: 0};

function getNextImage(){

   var j = StartVal.value;
   var tmpStr = "";

   //Code avoids loading the same image twice, maing sure the latest (assume last) photo is first
   //Showing the photos in random order, but not repeating until all unique have been viewed

   if (NumSeen.value == WMI_WELCOME_IMG.length){
      SeenIt.value = "-";
      NumSeen.value = 0;
   }

   if (StartVal.value == -1){
      j = (WMI_WELCOME_IMG.length - 1);
      StartVal.value = j;
   }else{
      tmpStr = SeenIt.value;

      do{
         j=parseInt(Math.random()*WMI_WELCOME_IMG.length);
         j=(isNaN(j))?0:j;
      } while (tmpStr.indexOf("-"+j+"-") >= 0)
   }

   SeenIt.value += j + "-";

   return(WMI_WELCOME_IMG[j]);
}

function SwitchImage(place){
   var interval = 5000;
   var new_image = getNextImage();

   document[place].src = new_image;
   NumSeen.value++;

   var recur_call = "SwitchImage('"+place+"')";
   timerID = setTimeout(recur_call, interval);
}

