//*********************************************
// JavaScript random image display with optional links, alt and title attributes
// Roland Jaeckel, 10/12/2004
// Image definition:
// image name pipe (|) URL pipe (|) alt/title attribute
// define number of random images - if images are arranged in descending order
// setting the number to less than the number of icons will make the first n icons static
var numImages = 7;
var ranImage = new Array;
// Add images here 
//ranImage[n] = 'filename-without-extension|link-or-empty-if-none|img-alt-text';
ranImage[0] = 'ib-link1||ORL Image ';
ranImage[1] = 'ib-link2||ORL Image ';
ranImage[2] = 'ib-link3||ORL Image ';
ranImage[3] = 'ib-link4||ORL Image ';
ranImage[4] = 'ib-link5||ORL Image ';
ranImage[5] = 'ib-link6||ORL Image ';
ranImage[6] = 'ib-link7||ORL Image ';
ranImage[7] = 'ib-link8||ORL Image ';
ranImage[8] = 'ib-link9||ORL Image ';
ranImage[9] = 'ib-link10||ORL Image ';
ranImage[10] = 'ib-link11||ORL Image ';
ranImage[11] = 'ib-link12||ORL Image ';
ranImage[12] = 'ib-link13||ORL Image ';
ranImage[13] = 'ib-link14||ORL Image ';
ranImage[14] = 'ib-link15||ORL Image ';
ranImage[15] = 'ib-link16||ORL Image ';


// Timed change of images:
// change evry 10 seconds
//setInterval('change_image("iblink",false, 1,'jpg')',10000);
// untimed, single random images:
change_image('iblink',false,1,'jpg');

// FUNCTION change_image
//
// parameters:
// imgprefix -> object name in DOM, ID attribute
// linksOn   -> true, false
// offset    -> object name offset
// imgType   -> extension jpg, gif, png
//
function change_image(imgprefix, linksOn, offset, imgType){
    // shuffle with Fisher Yates algorithm
    fisherYates(ranImage);

    var i = 0;

    // read source from first image
    var path=new String(document.images['iblink00'].src);

    // get the path to the graphics folder
    path = path.substring(0,path.lastIndexOf("/")+1);

    while (i<numImages){
        // split info on pipe 
        var tempArray = ranImage[i].split("|")
        // set image
        document.images['iblink0'+i].src = path+tempArray[0]+'.'+imgType; 
        // set link and get it as object by id if linksOn is true
        if (linksOn == true) {
            thisLink = document.getElementById('sp10'+i);
            thisLink.href = tempArray[1];
        }
        // set alt attribute and title attribute
        document.images['iblink0'+i].setAttribute('alt',tempArray[2]);
        document.images['iblink0'+i].setAttribute('title',tempArray[2]);
        i++;
    }        
}

// Fisher-Yates randomize shuffle
function fisherYates ( myArray ) {
  var i = myArray.length;
  while ( i-- ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}
//*****************************************