//------- the previous and next buttons for the main picture ---------
function nextpic() {
    if ( ++curpic >= maxthm ) { curpic = 0; }
    putmainpic( curpic );
}

function prevpic() {   
    if ( --curpic < 0 ) { curpic = maxthm-1; }
    putmainpic( curpic );
}

//------ a click on a thumbnail cell to get larger image into main picture ------------
function putpic(objid) { // objid is the cell id that's been clicked on
    var s = "", j = 0;

    switch ( objid ) {
        case 'c1': nth = 0; break;
        case 'c2': nth = 1; break;
        case 'c3': nth = 2; break;
        case 'c4': nth = 3; break;
        default: nth = maxthm-1; //Math.round( 5 * Math.random());
    }
    j = topthm + nth;
    if ( j >= maxthm ) { j -= maxthm; }

    curpic = j; // need to keep track of which main image is currently displayed
    putmainpic( curpic );
}

//------- put the main picture and associated text into place ---------------
function putmainpic(j) {
    var s = "";
    var txtbox = document.getElementById( "ptxt" ); // ptxt is the id of the text element associated with main picture

    if ( ! pix[j].src ) {
        pix[j].src = imgdir + "/"+picnams[j]+".jpg";
    }
    document.mpic.src = pix[j].src;
    s = pictitl[j];
    if (  s == "." ) { s = ""; }
    txtbox.innerHTML = s;  // txtbox.firstChild.nodeValue = s;
}

//------------- set the top thumbnail image and text -------------------
function settopthum( n ) {
    var s = "", txtbox = document.getElementById( "c1txt" );
    topthm = n;
    document.c1.src = thms[topthm].src;
    s = thmtitl[topthm];
    if (  s == "." ) { s = ""; }
    txtbox.firstChild.nodeValue = s;

    set23boxes();
}

//--------- scroll and reset top thumbnail image and text -----------------
function scrollthum() {
    var s = "", txtbox = document.getElementById( "c1txt" );
    if ( ++topthm >= maxthm ) { topthm = 0; }
    document.c1.src = thms[topthm].src;
    s = thmtitl[topthm];
    if (  s == "." ) { s = ""; }
    txtbox.firstChild.nodeValue = s;

    set23boxes();
}
function scrolldown() {
    var s = "", txtbox = document.getElementById( "c1txt" );
    if ( --topthm < 0 ) { topthm = maxthm-1; }
    document.c1.src = thms[topthm].src;
    s = thmtitl[topthm];
    if (  s == "." ) { s = ""; }
    txtbox.firstChild.nodeValue = s;

    set23boxes();
}
function resetthum() {
    var s = "", txtbox = document.getElementById( "c1txt" );
    topthm = 0;
    document.c1.src = thms[topthm].src;
    s = thmtitl[topthm];
    if (  s == "." ) { s = ""; }
    txtbox.firstChild.nodeValue = s;

    set23boxes();
}

//--------------- set the remaining thumbnail images and text ---------------
function set23boxes() {
    var s = "", txtbox = document.getElementById( "c2txt" );
    nth = topthm + 1;
    if ( nth >= maxthm ) { nth = 0; }
    document.c2.src = thms[nth].src;
    var s = thmtitl[nth];
    if (  s == "." ) { s = ""; }
    txtbox.firstChild.nodeValue = s;

    if ( ++nth >= maxthm ) { nth = 0; }
    txtbox = document.getElementById( "c3txt" );
    document.c3.src = thms[nth].src;
    s = thmtitl[nth];
    if (  s == "." ) { s = ""; }
    txtbox.firstChild.nodeValue = s;

    if ( document.c4.src ) {
        if ( ++nth >= maxthm ) { nth = 0; }
        txtbox = document.getElementById( "c4txt" );
        document.c4.src = thms[nth].src;
        s = thmtitl[nth];
        if (  s == "." ) { s = ""; }
        txtbox.firstChild.nodeValue = s;
    }
}
//-------- set the button images according to the condition of the mouse button ------
function b1upsrc() {
    document.b1.src = btns[0].src;
}
function b2upsrc() {
    document.b2.src = btns[1].src;
}
function b3upsrc() {
    document.b3.src = btns[2].src;
}
function b1dnsrc() {
    document.b1.src = btns[3].src;
}
function b2dnsrc() {
    document.b2.src = btns[4].src;
}
function b3dnsrc() {
    document.b3.src = btns[5].src;
}
// -- previous -- next -------
function b4upsrc() {
    document.b4.src = btns[6].src;
}
function b4dnsrc() {
    document.b4.src = btns[7].src;
}
function b5upsrc() {
    document.b5.src = btns[8].src;
}
function b5dnsrc() {
    document.b5.src = btns[9].src;
}


