﻿

//only shows the required banner image
function showLPBannerImage(id) {
    LPBannersHideAll();

    var bannerImage = document.getElementById('divLPBannerImage' + id);
    if (bannerImage != null) {
        //bannerImage.setAttribute('style', 'display:block;')
        bannerImage.style.display = 'block';
        var seconds = bannerImage.getAttribute('title');
        if (seconds == null) { seconds = 5; }
        InitializeTimer(seconds);
        return false;
    } else {
        //we cannot find the item and if its requesting 1 we may not have an image
        if (id==1) {
            //no image so break
            return false;
        }
    }
    
    //if we are here we could find the next banner image so lets start again
    showLPBannerImage(1);
}

//determines which banner image is currently showing and then 
//displays the next one
function showLPBannerNext() {
    var id = 0
    //get the current showing
    id = LPBannersGetDisplay(id);

    // hid them all
    LPBannersHideAll();

    // show the next one
    showLPBannerImage(++id);

    return false;
}

//returns the id of the currently displayed banner immage
function LPBannersGetDisplay(id) {
    var count = 1
    var bannerImageOff = document.getElementById('divLPBannerImage' + count);

    while (bannerImageOff != null) {
        //if (bannerImageOff.getAttribute('style', 'display').toLowerCase().indexOf('block',0) > -1)
        if (bannerImageOff.style.display=='block')
        {
            id = count;
            return id;
        }
        count++;
        bannerImageOff = document.getElementById('divLPBannerImage' + count);
        //catch all to exit if we have a problem
        if (count == 100) { id = 0; break; }
    }
}

//turns off all banner images
function LPBannersHideAll() {
    var count = 1
    var bannerImageOff = document.getElementById('divLPBannerImage' + count);

    while (bannerImageOff != null) {
        //bannerImageOff.setAttribute('style', 'display:none;');
        bannerImageOff.style.display = 'none';
        count++;
        bannerImageOff = document.getElementById('divLPBannerImage' + count);
        //catch all to exit if we have a problem
        if (count == 100) { break; }
    }
}


//------------------------------------------
// Timer Functions
//------------------------------------------
var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer(seconds) {
    // Set the length of the timer, in seconds
    secs = seconds
    StopTheClock()
    StartTheTimer()
}

function StopTheClock() {
    if (timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer() {
    if (secs == 0) {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        showLPBannerNext();
    }
    else {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}



