// =======================================================================
// This function randomly replaces the images in the header image element.
// =======================================================================
function loadHeaderImages ()
{
	// An array of available header images
    var imgArray = [
        "3dsymbol", "bluemood",  "compass", "gateway",
        "gpsunit",  "hitech",    "paper",   "platmap",
        "plotter",  "searching", "sextant", "starmaps" ] ;

	// Parse a specified header image to get the name of the image folder
	var imgElement = document.getElementById("headerimage0") ;
	var imgFolderPath = imgElement.src ;
	imgFolderPath = imgFolderPath.substring(0, imgFolderPath.lastIndexOf("/") + 1) ;

    // Update each header image slot of which there are (5)
    // If the number should ever change, the script should be modified
    // to query the list of images attached to the table cell.
    for (var i = 0 ; i < 5 ; i++)
    {
		// Get an index to an image not already used
        var imgIndex = Math.floor (Math.random () * imgArray.length) ;

        while (imgArray[imgIndex] == null)
        {
            imgIndex = Math.floor (Math.random () * imgArray.length) ;
        }

        // Modify this header image slot to reference the indexed image
        imgElement = document.getElementById("headerimage" + i) ;
        imgElement.src = imgFolderPath + imgArray[imgIndex] + ".jpg" ;

        // Nullify this entry array so it doesn't get used by another
        // header image slot
        imgArray[imgIndex] = null ;
    }
}
