// JavaScript Document
// Description: Home Random Image Loader
// Author: Travis Cunningham
// Date: March 2009

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
// Function that return a number between 0 and "nums - 1"
function getRandom(nums){
    var ranNum= Math.round(Math.random()*nums);
    return ranNum;
}

function getImage(){
    if(document.getElementById('homeFeatImage')){
        // Set number available (offset by 1 as it starts at 0)
        var numberOfImages    = 3;
        var randomNumber      = getRandom(numberOfImages);
        
        // Create an array to hold the names of all images.
        var image = new Array(numberOfImages);
        image[0]="../images/2009/homeFeat/home1.jpg";
        image[1]="../images/2009/homeFeat/home2.jpg";
        image[2]="../images/2009/homeFeat/home3.jpg";
        image[3]="../images/2009/homeFeat/home4.jpg";
        
        // Write the img tag with a random image name.
        var img = document.createElement('img');
        img.setAttribute('src',image[randomNumber]);
        img.setAttribute('width','623');
        img.setAttribute('height','463');
        var imgOutput = document.getElementById('homeFeatImage');
        imgOutput.appendChild(img);
    }
}
addLoadEvent(getImage);