// Copyright 2006 -- Web-Strategi Inc. Park Ridge, IL

// create the image and get reference to it as an object
document.write('<a href="#" id="rotator_link"><img id="rotator" width="'+width+'" height="'+height+'" src="" border="0" name="SlideShow"/></a>');
var img_obj = document.getElementById("rotator");
var link_obj = document.getElementById("rotator_link");

// the pics[] array is defined in the "image_config.js" file
var num_pics = pics.length;


// which image to show first
var random_num = Math.floor(num_pics*Math.random());

// swap_delay is defined in the "image_config.js" file
if (swap_delay != 0) {
    if (isNaN(swap_delay) || (swap_delay < 0)) {
        alert("For image swapping to work, the swap_delay must be a positive number.");
    }
    else {
        // swap delay is turned on and working
        
        var pic_objects =new Array();
    
        // this loop pre-loads all of the graphics so they will be in 
        // the browser's cache so there will be no delay in swapping them in and out
        for(i=0 ; i<num_pics ; i++){
            pic_objects[i]  = new Image();
            pic_objects[i].src = pics[i];
        }
        
        // first image displayed is one of the preloaded ones
        img_obj.src = pic_objects[random_num].src;
        link_obj.href = urls[random_num];
        
        setInterval("swap()",1000*swap_delay);
    }
}
else { 
    // swapping is turned off, so we just want to load an initial random image without preloading
    img_obj.src = pics[random_num];

}


function swap() {
    // turning off random order for now
    //var new_num = random_num;
    // we don't want to put the same image in twice in a row
    //while (new_num == random_num) {
    //    new_num = Math.floor(num_pics*Math.random());
    //}
    //random_num = new_num;
    if (random_num < num_pics -1) {
        random_num++;
    }
    else {
        random_num = 0;
    }
    var new_num = random_num;
    
    if (document.all) {
        document.images.SlideShow.style.filter="blendTrans(duration=2)";
        document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
        document.images.SlideShow.filters.blendTrans.Apply();
    }
    
    img_obj.src = pic_objects[new_num].src;
    link_obj.href = urls[new_num];
    
    if (document.all) {
        document.images.SlideShow.filters.blendTrans.Play();
    }
}

       

