<!--
var secs
var timerID = null
var timerRunning = false
var tick = 1000
var delayInSeconds = 3
var aryImages;
var aryImageCaptions;
var curImage = 0;
useCaptions = true;

function InitializeImages( imagesDir, imagesSeq, numImages )
{
    // don't use captions for homepage
    if( imagesSeq == "000" )
        useCaptions = false;

    // 999 is maximum num of images per collection
    numImages = Math.min( 999, numImages )
    firstPass = Math.min( 9, numImages )
    aryImages = new Array(numImages)
    
    if( useCaptions )
        aryImageCaptions = new Array(numImages)
    for( n = 1; n <= firstPass; n++ )
    {
        aryImages[n-1] = imagesDir + "/" + imagesSeq + "_00" + n + ".jpg"
        if( useCaptions )
            aryImageCaptions[n-1] = imagesDir + "/" + imagesSeq + "_00" + n + "c.jpg"
    };
    if( numImages >= 10 )
    {
        secondPass = Math.min( 99, numImages )
        for( n = 10; n <= secondPass; n++ )
        {
            aryImages[n-1] = imagesDir + "/" + imagesSeq + "_0" + n + ".jpg"
            if( useCaptions )
                aryImageCaptions[n-1] = imagesDir + "/" + imagesSeq + "_0" + n + "c.jpg"
        }
        if( numImages >= 100 )
        {
            for( n = 100; n <= numImages; n++ )
            {
                aryImages[n-1] = imagesDir + "/" + imagesSeq + "_" + n + ".jpg"
                if( useCaptions )
                    aryImageCaptions[n-1] = imagesDir + "/" + imagesSeq + "_" + n + "c.jpg"
            }
        }
    }
};

// increments and loops the image index, then sets the main image src
function SwapImage( forward )
{
    if( forward )
        curImage++
    else
        curImage--
    if( curImage > aryImages.length - 1 )
        curImage = 0
    else if( curImage < 0 )
        curImage = aryImages.length - 1
    document.images["main_image"].src = aryImages[curImage];
    if( useCaptions )
        document.images["main_image_caption"].src = aryImageCaptions[curImage];
}

// starts the timed image swapping loop
// TODO: introduce pause here
function InitializeTimer()
{
    secs = delayInSeconds
    StopTheClock()
    StartTheTimer()
}

// clears the javascript timeout
function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

// one tick...when timer gets to 0, swaps image and resets
function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        SwapImage( true )
        InitializeTimer()
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", tick)
    }
}

// should be called on doc load in <body>
function Init( imagesDir, imagesSeq, numImages, isTimed )
{
    InitializeImages( imagesDir, imagesSeq, numImages )
    if( isTimed )
        InitializeTimer()
}
//-->
