//
// boinkWriteHTMLHeader(): write out a standard BOINK! HTML header.
//
function boinkWriteHTMLHeader(doc, root, title)
{
    // Write a standard header
    doc.clear();
    doc.writeln("<html>");
    doc.writeln("<head>");
    doc.writeln("<title>" + title + "</title>");
    doc.writeln("<meta name=\"Author\" content=\"Matt Fahrner\">");
    doc.writeln("<script language=\"JavaScript1.2\" type=\"text/javascript\" src=\"" + root + "/boinkfuncs.js\">");
    doc.writeln("</script>");
    doc.writeln("<link href=\"" + root + "/standard.css\" rel=\"styleSheet\" type=\"text/css\">");
    doc.writeln("</head>");
    doc.writeln("<body>");
}

//
// boinkWriteHTMLFinish(): write out finishing BOINK! HTML block.
//
function boinkWriteHTMLFinish(doc, root)
{
    // Finish and close the document
    doc.writeln("<br clear=\"all\">");
    doc.writeln("<font size=\"1\">BOINK! Photography &COPY; 1999. All rights reserved. <a href=\"" + root + "/legal.html\" title=\"Legal Notices\">Legal terms</a>.</font>");
    doc.writeln("</body>");
    doc.writeln("</html>");
    doc.close();
}

//
// boinkPopImage(): pop up an image.
//
function boinkPopImage(root, imgname)
{
    // Default to horizontal settings
    var format = "Horizontal";
    var iheight = 287;
    var iwidth = 432;
    // Override if vertical
    if (imgname.substr(0, 1) == "v") {
	var format = "Vertical";
	iheight = 432;
	iwidth = 287;
    }

    // Pop up a window
    var popwin = window.open("", "boinkViewPicture", "height=" + (iheight + 170) + ",width=" + (iwidth + 20));
    boinkWriteHTMLHeader(popwin.document, root, imgname);
    popwin.document.writeln("<center>");
    popwin.document.writeln("<font size=1 color=red>Click on image to close.</font><p>");
    // This table adds a white border
    popwin.document.writeln("<a href='JavaScript:self.close()'>");
    popwin.document.writeln("<img src=\"imgmedium/" + imgname + "\" height=" + iheight + " width=" + iwidth + " border=0>");
    popwin.document.writeln("</a>");
    popwin.document.writeln("<br><font size=\"2\">Image: " + imgname.substr(6, 9) + "<br>");
    popwin.document.writeln("Format: " + format);
    if (imgname.substr(1, 1) == "b")
        popwin.document.writeln("35mm Black & White");
    else
        popwin.document.writeln(" 35mm Color Transparency");
    popwin.document.writeln("<br>");
    popwin.document.writeln("&COPY; " + imgname.substr(2, 4));
    if (imgname.substr(6, 3) == "mwf")
        popwin.document.writeln(" Matt Fahrner, ");
    popwin.document.writeln(" BOINK! Photography<br>");
    popwin.document.writeln("</font>");
    //popwin.document.writeln("</center>");
    boinkWriteHTMLFinish(popwin.document, root);
}

//
// boinkFormatPhotoArray(): formats an array of photos.
//
function boinkFormatPhotoArray(root, photolist)
{
    // Make sure the slide images are pre-loaded/pre-cached
    smv_01 = new Image();
    smv_01.src = "/images/smv_01.gif";
    smv_02 = new Image();
    smv_02.src = "/images/smv_02.gif";
    smv_03 = new Image();
    smv_03.src = "/images/smv_03.gif";
    smv_04 = new Image();
    smv_04.src = "/images/smv_04.gif";
    smv_05 = new Image();
    smv_05.src = "/images/smv_05.gif";
    smh_01 = new Image();
    smh_01.src = "/images/smh_01.gif";
    smh_02 = new Image();
    smh_02.src = "/images/smh_02.gif";
    smh_03 = new Image();
    smh_03.src = "/images/smh_03.gif";
    smh_04 = new Image();
    smh_04.src = "/images/smh_04.gif";
    smh_05 = new Image();
    smh_05.src = "/images/smh_05.gif";

    // Build tables from the array
    for (i = 0; i < photolist.length; ++i) {
       // Check for vertical orientation, otherwise assume horizontal
       document.writeln("<table border=0 cellpadding=0 cellspacing=0 align=\"left\">");
       if (photolist[i].substr(0, 1) == "v") {
	    document.writeln("<tr>");
	    document.writeln("<td colspan=3>");
	    document.writeln("<img src=\"" + root + "/images/smv_01.gif\" width=152 height=22></td>");
	    document.writeln("</tr>");
	    document.writeln("<tr>");
	    document.writeln("<td rowspan=2>");
	    document.writeln("<img src=\"" + root + "/images/smv_02.gif\" width=40 height=129></td>");
	    document.writeln("<td>");
            // Actual Image goes here! Must be 72x107
            document.writeln("<a href=\"JavaScript:boinkPopImage('" + root + "', '" + photolist[i] + "')\">");
	    document.writeln("<img src=" + "imgsmall/" + photolist[i] + " width=72 height=107 border=0 alt=\"" + photolist[1] + "\"></a></td>");
	    document.writeln("<td rowspan=2>");
	    document.writeln("<img src=\"" + root + "/images/smv_04.gif\" width=40 height=129></td>");
	    document.writeln("</tr>");
	    document.writeln("<tr>");
	    document.writeln("<td>");
	    document.writeln("<img src=\"" + root + "/images/smv_05.gif\" width=72 height=22></td>");
	    document.writeln("</tr>");
       } else  {
	    document.writeln("<tr>");
	    document.writeln("<td colspan=3>");
	    document.writeln("<img src=\"" + root + "/images/smh_01.gif\" width=151 height=40></td>");
	    document.writeln("</tr>");
	    document.writeln("<tr>");
	    document.writeln("<td rowspan=2>");
	    document.writeln("<img src=\"" + root + "/images/smh_02.gif\" width=22 height=112></td>");
	    document.writeln("<td>");
            // Actual Image goes here! Must be 107x72
            document.writeln("<a href=\"JavaScript:boinkPopImage(\'" + root + "', \'" + photolist[i] + "')\">");
	    document.writeln("<img src=" + "imgsmall/"+ photolist[i] + " width=107 height=72 border=0 alt=\"" + photolist[i] + "\"></a></TD>");
	    document.writeln("<td rowspan=2>");
	    document.writeln("<img src=\"" + root + "/images/smh_04.gif\" width=22 height=112></td>");
	    document.writeln("</tr>");
	    document.writeln("<tr>");
	    document.writeln("<td>");
	    document.writeln("<img src=\"" + root + "/images/smh_05.gif\" width=107 height=40></td>");
	    document.writeln("</tr>");
       }
       document.writeln("</table>");
       if (i % 3 == 2)
	    document.writeln("<BR clear=all>");
    }
}

//
// boinkFormatPhotoList(): format a variable list of photos.
//
function boinkFormatPhotoList(root, pic1, picn)
{
    // Build an array from the arguments
    var photolist = new Array();
    for (i = 1,  j = 0; i < arguments.length; ++i)
	photolist[j++] = arguments[i];

    // Format as an array
    boinkFormatPhotoArray(root, photolist); 
} 

//
// boinkMakePhotoPage(): create a page of photos.
//
function boinkMakePhotoPage(root, title, pic1, picn)
{
    // Build an array from the arguments
    var photolist = new Array();
    for (i = 2, j = 0; i < arguments.length; ++i)
	photolist[j++] = arguments[i];

    // Write header, body, and end
    boinkWriteHTMLHeader(root, title);
    boinkFormatPhotoArray(root, photolist);
    document.writeln("<br><br><br>");
    boinkWriteHTMLFinish();
}
