// >album.js
// Copyright © 2008, 7th software
// All rights reserved.

var width = 4;

var img_path   = new Array;
var img_text   = new Array;
var page_title = "Photo album";
var page_link  = "";
var images     = 0;

function album(title, link)
{
  page_title = title;
  page_link  = link;
  images     = 0;
}

function album_image(path, caption)
{
  img_path[images] = path;
  img_text[images] = caption;
  images++;
}

function write_album(next)
{
  var row   = 0;
  var image = 0;

  if (next == '')
  {
    /* Page title */
    document.write("<h1>" + page_title + "</h1>");
    /* Outline div */
    document.write("<div class='oddbox' style='text-align: center; padding: 16px; margin: 16px;'>");
    /* Thumbnails table */
    document.write("<table class='offbox' background='white' align='center' valign='middle' border='0' cellpadding='16' cellspacing='0'>");
  }

  while (image < images)
  {
    var follow   = image + 1 >= images ? 0 : image + 1;
    var enc_cap  = escape("\"" + img_text[image] + "\"");
    var enc_uri  = escape("./photos/" + img_path[image]);
    var my_uri   = "./photo.html?album=" + page_link + "&photo=" + enc_uri + "&next=" + follow + "&quote=" + enc_cap

    if (next != '')
    {
      if (image == next)
      {
        window.location.assign(my_uri);
      }
    }
    else
    {
      if (!row)
        document.write("<tr align='center' valign='middle'>");
      document.write("<td class='offbox' width='160' height='160'>");
      document.write("<a href='" + my_uri + "' border='0'>");
      document.write("<img align='center' src='./thumbs/" + img_path[image] + "' border='0' ");
      document.write("alt=\"" + img_text[image] + "\" /></a>");
      document.write("</td>");
    }
    row++;
    if (row >= width)
    {
      document.write("</tr>");
      row = 0;
    }
    image++;
  }
  if (row)
    document.write("</tr>");
  /* End of tables */
  document.write("</table></div>");
}



