﻿var num = 0;
var currentPhotoId = 0;

function nextPhoto()
{
    getCurrentPhotoId();
    currentPhotoId++;
    if ( currentPhotoId >= aryImages.length )
    {
        currentPhotoId = 0;
    }
    LoadPhoto(currentPhotoId);
    SetImageWidth(currentPhotoId);

    return 0;
}

function prevPhoto()
{
    getCurrentPhotoId();
    currentPhotoId--;
    if ( currentPhotoId < 0 )
    {
        currentPhotoId = aryImages.length - 1;
    }
    LoadPhoto(currentPhotoId);
    SetImageWidth(currentPhotoId);

    return 0;
}

function getCurrentPhotoId()
{
    var currentImage = document.images['imgPhoto'].src;
    debug(currentImage, 'currentImage');
    if ( currentImage )
    {
        for ( i=0; i<aryImages.length; i++ )
        {
            if ( aryImages[i] == currentImage )
            {
                currentPhotoId = i;
                break;
            }
        }
    }

    return 0;
}

function LoadPhoto(num)
{

    document.getElementById('imgPhoto').src = aryImages[num];
    
    document.getElementById('imgCapt').firstChild.nodeValue = aryCapts[num];

    window.scrollTo(0,0);

    return 0;
}

function SetImageWidth(num)
{
    img = new Image();
    img.src = aryImages[num];

    // if the image width will overstep the boundry, limit the width, but not the height
    if ( (0 + img.width) > 400 )
    {
        document.getElementById('imgPhoto').width = '400';
    }
    else
    {
        if ( (0 + img.width) > 0 )
        {
            document.getElementById('imgPhoto').width = img.width;
        }
    }

    // unborder any thumbnails
    for ( i=0; i<aryImages.length; i++ )
    {
       document.getElementById('thumbNailClip' + i).className = 'thumbNailClip';
    }

    document.getElementById('thumbNailClip' + num).className = 'thumbNailClipHightlighted';

 
    return 0;
}


