<!--
//==============================================================
// START OF ANIMATION CODE
//==============================================================

//---------------------------------------------------------
// function cutArray(indx,arry)
//---------------------------------------------------------
function cutArray(indx,arry) {
  // CUT OUT A SINGLE ELEMENT WITH INDEX EQUAL TO "indx" OUT
  // OF THE ARRAY "arry" AND RETURN RESULTANT ARRAY
  newArry = new Array();
  if (indx == 0) {
    newArry = arry.slice(1);
  } else if (indx == arry.length - 1) {
    newArry = arry.slice(0,arry.length-1);
  } else {
    slice1 = new Array();
    slice2 = new Array();	
    slice1 = arry.slice(0,indx);
	slice2 = arry.slice(indx + 1);
	newArry = slice1.concat(slice2);
  }
  arry = newArry;
  return arry;
}

//---------------------------------------------------------
// function changeImage() 
//---------------------------------------------------------
function changeImage() {
   var index = imgIndex;
   
   document.images["topLeftImage"].src = imgURLs[index];         
   var newIndex = index + 1;
   if (newIndex > nImages - 1) { newIndex = 0; }
   imgIndex = newIndex;
      
   setTimeout('changeImage()', dwell[index] );
}  
  
//------------------------------------------------------
//function startAnimation()
//------------------------------------------------------
function startAnimation() {
   nLeft--;
   if (nLeft == 0) {
     setTimeout('changeImage()', dwell[imgIndex - 1] );
   }
}

//----------------------------------------------------------
// function preloadImages() 
//----------------------------------------------------------
function preloadImages() {
  imgArr = new Array();
  for (var i=0; i<nImages; i++) {
    imgArr[i] = new Image(220,239);
    imgArr[i].onload = startAnimation;
    imgArr[i].src = imgURLs[i];
  }
}

//----------------------------------------------------------
// function compatPush() 
//----------------------------------------------------------
function compatPush(into, elements) {
  var args = compatPush.arguments; 
  for (var i=1; i<args.length; i++) {
    var element = new Array(args[i]);
    into = into.concat(element);
  }
  return into;
}

//-----------------------------------------------
// END OF FUNCTIONS
//-----------------------------------------------

// DEFINE NUMBER OF IMAGES TO LOOP THROUGH
var nImages = 4;
var imgIndex = 1;

// LIST ALL OF THE AVAILABLE IMAGES TO LOOP THROUGH FOR THE TOP LEFT
allImages = new Array();

allImages = compatPush(allImages, "images/top/top-left/antarctica.gif");
allImages = compatPush(allImages, "images/top/top-left/wwlist.gif");
allImages = compatPush(allImages, "images/top/top-left/grddisp.gif");
allImages = compatPush(allImages, "images/top/top-left/hurricane.gif");
allImages = compatPush(allImages, "images/top/top-left/italy.gif");
allImages = compatPush(allImages, "images/top/top-left/radar.gif");
allImages = compatPush(allImages, "images/top/top-left/sfcplot.gif");
allImages = compatPush(allImages, "images/top/top-left/sst.gif");
allImages = compatPush(allImages, "images/top/top-left/uaplot.gif");
//allImages = compatPush(allImages, "images/top/top-left/front.gif");
allImages = compatPush(allImages, "images/top/top-left/msg.gif");
allImages = compatPush(allImages, "images/top/top-left/ivan_globe.gif");

// DECREASE nImages IF LESS THAN DEFAULT ARE AVAILABLE
if (allImages.length < nImages) { nImages = allImages.length; }
nLeft = nImages;

// DEFINE DWELL RATES FOR IMAGES IN ANIMATION
dwell = new Array();
for (var i=0; i<nImages-1; i++) {
  dwell[i] = parseInt(2 * 1000);  // milliseconds
}
dwell[i] = parseInt(3 * 1000);  // milliseconds

// RANDOMLY PICK nImages IMAGES TO LOOP THROUGH
imgURLs = new Array();
var index;

for (var i = 0; i < nImages; i++) {
  index = Math.floor(Math.random() * allImages.length);
  imgURLs[i] = allImages[index];
  allImages = cutArray(index,allImages);
}

// FORCE FIRST IMAGE
imgURLs[0] = "images/top/top-left/hi_res_wi.gif";
//-->
