﻿// CUMC Homage Page Banner - Dynamic Image Swap

var navImages = new Array( // Add the URL for each image below
    "http://cumc.columbia.edu/img-cumc/banner/cumc_clinical.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_clinical_1.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_clinical_2.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_clinical_3.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_campus.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_campus_1.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_campus_2.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/ccumc_students.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_students_1.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_people.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_people_1.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_people_2.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_graduation.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_graduation_1.jpg",
    "http://cumc.columbia.edu/img-cumc/banner/cumc_graduation_2.jpg"
);

// Variable Decleration
//  Image selection variables
var numImgs = navImages.length;
var ran_number = Math.floor(Math.random() * numImgs);

// Countdown variables
var x = 5 // # of seconds before refresh
var y = 1 // rate of time to be subtracted every second


function ImageRotate(){ // select a random image and assign it to the src for the banner

    document.images['imageBanner'].src = navImages[ran_number];

}


function startClock(){ // start the countdown and swap

    x = x-y; // decrement the time variable
    setTimeout("startClock()", 1000); // timeout the function for 1 second

    if( x==0 ){ //time to swap the image
    
        //alert( "Changing Image"+'http://cumc.columbia.edu/img-cumc/banner/'+navImages[ran_number] );
        
        document.images['imageBanner'].src = navImages[ran_number];
        ran_number = Math.floor(Math.random() * numImgs);
        x=5;

    } 

}
