var currentGalleryThumbnail;
var lastClickedGalleryThumbnail;

function mouseoverGalleryThumbnail(i, s, c)
{
    // only mouseover if nothing has been "clicked"
    if (i && i.className && !lastClickedGalleryThumbnail && i!=currentGalleryThumbnail) {
        if (currentGalleryThumbnail){
            currentGalleryThumbnail.className = 'galleryThumbnailPlain';
        }
        i.className='galleryThumbnailShown';
        showGalleryPicture(i, s, c);
        return false;
    } else {
        return true;
    }
}

function showGalleryPicture(i, s, c)
{
    var img = document.getElementById("mainPic");
    var div = document.getElementById("mainPicCaption");
    img.src = s;
    div.innerHTML = c;
    currentGalleryThumbnail = i;
}

function clickGalleryThumbnail(i, s, c){
    if (i && i.className) {
        // has something already been "clicked"
        if (lastClickedGalleryThumbnail){
            // has the previous "clicked" thumbnil been clicked yet again
            if (i == lastClickedGalleryThumbnail){
                lastClickedGalleryThumbnail = null;
            } else {
                lastClickedGalleryThumbnail.className='galleryThumbnailPlain';
                lastClickedGalleryThumbnail = i;
            }
        } else {
            lastClickedGalleryThumbnail = i;
        }
        if (i==lastClickedGalleryThumbnail){
           i.className='galleryThumbnailClicked';
        } else {
           i.className = 'galleryThumbnailShown'
        }
        showGalleryPicture(i, s, c);
        return false;
    } else {
        return true;
    }
}


