var imageNum = -1; /*Keep track of image rotation*/
var id; /*ID of image element*/
var sec; /*Time between image changes*/
var imageSrc; /*Image and Link array*/

function changeImage(image, mil, array, linkID){
    id = image; /*Set ID of image element*/
    sec = mil; /*Set time between image changes*/
    imageSrc = array; /*Set image source and link source array*/
    link = linkID /*Set ID of link*/
       
    /*Pre-Load images to make fading smoother*/
    if (document.images){
       var i = 0;
       for(i=0; i<imageSrc.length -1; i++) 
         preload_image_object = new Image();
         preload_image_object.src = imageSrc[i][0];
    }
    
    setTimeout('fadeImage()',sec); /*Fade away the holder image*/
    setTimeout('nextImage()',sec + 2800); /*Get first image in array*/
    setTimeout('showImage()',sec + 3500); /*Show first image*/
    setTimeout('loopImage()',sec + 3501); /*Start image change loop*/
}

function loopImage(){
    setTimeout('fadeImage()',sec + 3000); /*Fade image after being shown for user-set duration*/
    setTimeout('nextImage()',sec + 5800); /*Get next image*/
    setTimeout('showImage()',sec + 6500); /*Show next image */
    setTimeout('loopImage()',sec + 7501); /*Recursive call*/
}
          
function fadeImage(){
  new Effect.Fade(id,{duration:3.0}); /*Create fade object*/
}
function showImage(){
   new Effect.Appear(id,{duration:3.0}); /*Create Appear object*/
}

function nextImage(){
    if (imageNum < imageSrc.length -1){ /*Check if at the end of the array*/
        imageNum++; /*Take next step in the array*/
    }
    else{ /*At the end of the array, start over*/
        imageNum = 0; /*Move to the start of the array*/
    }
    document.getElementById(id).src = imageSrc[imageNum][0]; /*Set image source to new image*/
    document.getElementById(link).href = imageSrc[imageNum][1]; /*Set link href to new url*/
}

