//Function runs when this page has been loaded and does the following:
//1. Determine the browser name and version
// (since the script will only work on Netscape 3+ and Internet Explorer 4+).
//2. Start the timer object that will periodically change the image displayed
// by the Banner Ad.
//3. Preload the images used by the Banner Ad rotator script
function InitialiseBannerAdRotator() {
    //Determine the browser name and version
    //The script will only work on Netscape 3+ and Internet Explorer 4+
    var BrowserType = navigator.appName;
    var BrowserVersion = parseInt(navigator.appVersion);
    if (BrowserType == "Netscape" && (BrowserVersion >= 3)) {
        IsValidBrowser = true;
    }
    if (BrowserType == "Microsoft Internet Explorer" && (BrowserVersion >= 4)) {
        IsValidBrowser = true;
    }
    if (IsValidBrowser) {
        TimerObject = setTimeout("ChangeImage()", DisplayInterval);
        BannerAdCode = 0;
        for (i=0; i<NumberOfImages; i++) {
            BannerAdImages[i] = new Image();
            BannerAdImages[i].src = ' ' + ImageFolder + ImageFileNames[i];
            BannerAdImages[i].alt = ImageMouseOverTxt[i];   
            BannerAdImages[i].width=200;
        }
    }
    BannerAdImages.sort(randOrd);
    
    // reset the ImageURLs to match rendom array
    for(i=0; i<NumberOfImages; i++) {
        for(j=0; j<NumberOfImages; j++) {       
            if( BannerAdImages[i].alt == ImageMouseOverTxt[j] ) {
                CloneImageURLs[i] = ImageURLs[j];
            }
        }
    }      
}

function randOrd(){
    return (Math.round(Math.random())-0.5);
}

//Function to change the src of the Banner Ad image
function ChangeImage() {
    if (IsValidBrowser) {
        //BannerAdCode=Math.floor(Math.random()* NumberOfImages);        
        BannerAdCode = BannerAdCode + 1;
        if (BannerAdCode == NumberOfImages) {
            BannerAdCode = 0;
        }
        window.document.bannerad.src = BannerAdImages[BannerAdCode].src;
        window.document.bannerad.alt = BannerAdImages[BannerAdCode].alt; 
        window.document.bannerad.width = BannerAdImages[BannerAdCode].width;        
        TimerObject = setTimeout("ChangeImage()", (DisplayInterval * 1000));
    }

}

//Function to redirect the browser window/frame to a new location,
//depending on which image is currently being displayed by the Banner Ad.
//If Banner Ad is being displayed on an old browser then the DefaultURL is displayed
function ChangePage() {
    if (IsValidBrowser) {
        if (TargetFrame != '' && (FramesObject)) {
            FramesObject.location.href = CloneImageURLs[BannerAdCode];
        } else {
            if (TargetFrame == '_blank') {
                window.open(CloneImageURLs[BannerAdCode]);
            } else if (TargetFrame == '_self') {
                document.location = CloneImageURLs[BannerAdCode];
            } else if (TargetFrame == '_parent') {
                window.parent.document.location = CloneImageURLs[BannerAdCode];
            } else if (TargetFrame == '_top') {
                window.top.document.location = CloneImageURLs[BannerAdCode];
            } else {
                document.location = CloneImageURLs[BannerAdCode];
            }
        }
    } else if (!IsValidBrowser) {
        document.location = DefaultURL;
    }
}

