// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com
// Created by: Ultimater :: http://ultimiacian.tripod.com/
// Add this snippet to the very beginning of your script.
if(!document.getElementById)
{
  if(document.all)
  {
    document.getElementById=function()
    {
      if(typeof document.all[arguments[0]]!="undefined")
      {
        return document.all[arguments[0]];
      }
      else
      {
        return null;
      }
    }
  }
  else if(document.layers)
  {
    document.getElementById=function()
    {
      if(typeof document[arguments[0]]!="undefined")
      {
        return document[arguments[0]];
      }
      else
      {
        return null;
      }
    }
  }
}

//  Image gallery script written by Reuben Bradley (turonah@yahoo.com)
//  Free for use provided that proper credit is given.

imgDir = "images/gallery/";   // Leave blank if not needed
maxCols = 5;
curInd = 0;

projImgs = new Array();
// -- Begin image array initialization --
// Syntax used for the images is as follows:
//  "desc"  - description to be displayed below and as the "alt" for the image
//  "tsrc"  - thumbnail source
//  "src"   - full-size picture source
// Each image "object" requires the above three properties, and needs to
//  be added to the projImgs array.

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image01.jpg";
img["src"]  = "image01.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image02.jpg";
img["src"]  = "image02.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image03.jpg";
img["src"]  = "image03.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image04.jpg";
img["src"]  = "image04.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image05.jpg";
img["src"]  = "image05.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image06.jpg";
img["src"]  = "image06.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image07.jpg";
img["src"]  = "image07.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image08.jpg";
img["src"]  = "image08.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image09.jpg";
img["src"]  = "image09.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image10.jpg";
img["src"]  = "image10.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image11.jpg";
img["src"]  = "image11.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image12.jpg";
img["src"]  = "image12.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image13.jpg";
img["src"]  = "image13.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image15.jpg";
img["src"]  = "image15.jpg";
projImgs[projImgs.length] = img;

img = new Object();
img["desc"] = "";
img["tsrc"] = "t_image16.jpg";
img["src"]  = "image16.jpg";
projImgs[projImgs.length] = img;

// -- End image array initialization --

// Change the main image and the description below it
function swapMainImg(newsrc, newdesc)
{
  img = document.getElementById("gal_img");
  img.src = newsrc;
  desc = document.getElementById("gal_desc");
  desc.innerHTML = "<p>" + newdesc + "</p>";
}

// Swap the main image for the one at a given index
function viewImage(ind)
{
  curInd = ind;
  swapMainImg(imgDir + projImgs[ind]["src"], projImgs[ind]["desc"]);
}

// Swap the main image for the next one in the array
function viewNextImg()
{
  curInd++;
  if(curInd >= projImgs.length)
  {
    curInd = 0;
  }
  viewImage(curInd);
}

// Swap the main image for the previous one in the array
function viewPrevImg()
{
  if(curInd == 0)
  {
    curInd = projImgs.length - 1;
  }
  else
  {
    curInd--;
  }
  viewImage(curInd);
}

// Write the code for the image gallery thumbnails
function writeTableCode()
{
  codeStr = "<table id=\"gal_tbl\" summary=\"Image Thumbnails\">\n\t<tr>\n";
  codeStr += "\t\t<td colspan=\"" + maxCols + "\">\n";
  codeStr += "\t\t\t<img id=\"gal_img\" src=\"" + imgDir + 
      projImgs[0]["src"] + "\" alt=\"" + projImgs[0]["desc"] + "\" />\n";
  codeStr += "\t\t\t<div id=\"gal_desc\"><p>" + projImgs[0]["desc"] + 
      "</p></div>\n";
  codeStr += "\t\t</td>\n";
  codeStr += "\t</tr>\n\t<tr>\n";
  codeStr += "\t\t<td style=\"text-align: left; \">\n";
  codeStr += "\t\t\t<a href=\"javascript:viewPrevImg();\">Prev</a>\n";
  codeStr += "\t\t</td>\n";
  codeStr += "\t\t<td colspan=\"" + (maxCols - 2) + "\"></td>\n";
  codeStr += "\t\t<td style=\"text-align: right; \">\n";
  codeStr += "\t\t\t<a href=\"javascript:viewNextImg();\">Next</a>\n";
  codeStr += "\t\t</td>\n";
  codeStr += "\t</tr>\n\t<tr>\n";
  colNum = 0;
  for(x = 0; x < projImgs.length; x++)
  {
    if(colNum >= maxCols)
    {
      codeStr += "\t</tr>\n";
      codeStr += "\t<tr>\n";
      colNum = 0;
    }
    codeStr += "\t\t<td>\n";
    codeStr += "\t\t\t<a href=\"javascript:viewImage('" + x + "')\">";
    codeStr += "<img src=\"" + imgDir + projImgs[x]["tsrc"] + 
        "\" alt=\"" + projImgs[x]["desc"] + "\" />";
    codeStr += "</a>\n";
    codeStr += "\t\t</td>\n";
    colNum++;
  }
  if(colNum < maxCols)
  {
    codeStr += "\t\t<td colspan=\"" + (maxCols - colNum) + "\"></td>\n";
  }
  codeStr += "\t</tr>\n</table>";
  
  document.write(codeStr);
}
