
// create the image and get reference to it as an object
document.write('<a href="#" id="rotator_link2"><img id="rotator2" width="'+width2+'" height="'+height2+'" src="" border="0" name="SlideShow2"/></a>');
var img_obj2 = document.getElementById("rotator2");
var link_obj2 = document.getElementById("rotator_link2");

// the pics2[] array is built in the "rotator2.js" file
var num_pics2 = pics2.length;


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

// swap_delay is defined in the "image_config.js" file
if (swap_delay2 != 0) {
    if (isNaN(swap_delay2) || (swap_delay2 < 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_objects2 =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_pics2 ; i++){
            pic_objects2[i]  = new Image();
            pic_objects2[i].src = pics2[i];
        }
        
        // first image displayed is one of the preloaded ones
        img_obj2.src = pic_objects2[curr_num2].src;
        link_obj2.href = urls2[curr_num2];
        
        setInterval("swap2()",1000*swap_delay2);
    }
}
else { 
    // swapping is turned off, so we just want to load an initial random image without preloading
    img_obj2.src = pics2[random_num2];

}


function swap2() {
    // the current image number is stored in curr_num
    // we calculate a new_num
    var new_num;
    if( random_or_cycle2 == 'random' ) {
        new_num = curr_num2;
        // we don't want to put the same image in twice in a row
        while (new_num == curr_num2) {
            new_num = Math.floor(num_pics2*Math.random());
        }
    }
    else { 
        // cycling through the images
        if (curr_num2 < num_pics2 -1) {
            new_num = curr_num2 + 1;
        }
        else {
            new_num = 0;
        }
    }
    curr_num2 = new_num;
    
    if (document.all) {
        document.images.SlideShow2.style.filter="blendTrans(duration=2)";
        document.images.SlideShow2.style.filter="blendTrans(duration=crossFadeDuration)";
        document.images.SlideShow2.filters.blendTrans.Apply();
    }
    
    img_obj2.src = pic_objects2[curr_num2].src;
    link_obj2.href = urls2[curr_num2];
    
    if (document.all) {
        document.images.SlideShow2.filters.blendTrans.Play();
    }
}

       

