// Set max columns in the thumbnail table here:
var maxCols = 6;

var names;
var altNames;

function startup() {
    var tbody = document.getElementById('thumbs');

    var col = 0;   
    var row;
    var i;
    for (i = 0; i < names.length; ++i, ++col) {
	if (col == maxCols)
	    col = 0;      
        if (col == 0) {
            row = document.createElement("tr");
	    tbody.appendChild(row);   
	}
	var cell = createCell();
	cell.align = "center";
	cell.valign = "top";
        row.appendChild(cell);

        var img = createThumb(i);
        cell.appendChild(img);
    }

    setLarge(0);
}

function createCell() {
    var cell = document.createElement("td");
    cell.width = 80;
    cell.height = 64;  
    cell.align = "left";
    // Other attributes of the TD can be set here
    return cell;
}

function createThumb(i) {
    var img = document.createElement("img");
    img.src = "images/" + names[i] + "_Sm.jpg";
    img.alt = altNames[i];
    img.border = 3;
    img.style.borderColor = "969696";
    img.onclick = function() { setLarge(i); };
    img.onmouseover = function() { img.style.borderColor = "#000099" }
    img.onmouseout = function() { img.style.borderColor = "969696"; }
    // other attributes of the 
    return img;
}

var currentIndex = 0;
function setLarge(index) {
    var large = document.getElementById("large");
    large.setAttribute("src", "images/" + names[index] + ".jpg");
    currentIndex = index;
    
    var textFrame = document.getElementById("textFrame");
    textFrame.src = "text/" + names[index] + ".html";
}

function textFrameLoaded() {
    var div = document.getElementById('largetext');
    var textFrame = document.getElementById("textFrame");
    var html = window.frames['textFrame'].document.body.innerHTML;
    div.innerHTML = html;
}

function rightArrow() {
    if (++currentIndex == names.length)
	currentIndex = 0;
    setLarge(currentIndex);	
}

function leftArrow() {
    if (currentIndex == 0)
	currentIndex = names.length - 1;
    else
	currentIndex--;
    setLarge(currentIndex);	
}

var closeupWindow;
function closeup() {
     if (closeupWindow)
closeupWindow.close();
     var url = "images/" + names[currentIndex]+ "_closeup.jpg";
     var html = "<html><body bgcolor='#d1b48f'><center><img src='" + url 
+ "'></center></body></html>";
     closeupWindow = window.open('', "PaintingCloseup", 
"width=475,height=475,top=0,left=350");
     closeupWindow.document.writeln(html);
     return false;
}


