/******** 
Build a Photo Gallery script to dynamically generate an HTML table with images.
By King Wilder
2008
*********/

var _imgName = Request.QueryString("id");
var _imgPath = "../images/photos/clients/";

var ns = (navigator.appName.indexOf('Netscape') > -1);
var id = (navigator.appName.indexOf('Microsoft Internet Explorer') > -1);
var imgs = new Array();

/*
You can run the getfiles.vbs script to generate the list automatically.
Read the help info in the file for more information.

Copy the data from the files.txt file in between the parentheses below.
Make sure there is NO comma before the closing parenthesis.

Bad  - '15',);
Good - '15');

*/
var imageItems = new Array(
'01',
'02',
'03',
'04',
'05',
'06',
'07',
'08',
'09',
'10',
'11',
'12',
'13',
'14',
'15'
    );

// Remove underscores from the file name.
function RemoveUnderscores(str) {
    try{
        var myStr = str.toString();
        return myStr.replace(/_/g, " ");
    }catch(e){
    
    }
    return str;
}

/*
This function makes the table for the Photo Gallery.
This script is executed in photos/index.html and photos/photos2.html
in the content area.

Arguments : 
-- startIndex - this is the number of the starting image.

-- count - this is the number of images to display on this page.  

-- columnCount - this is the number of columns in the table that will be created.
Example: 1 = one column, 2 = two columns, 4 = four columns, etc.  Don't use odd
numbered columns.  They don't display very well.  2 or 4 columns are best.

Example:
photos/index.html - MakeTable(1, 8, 2)
    startIndex  = 1 - start at the first image
    count       = 8 - display 8 images on this page
    columnCount = 2 - this is the number of columns in the table that is created
    
photos/photos2.html - MakeTable(9, 7, 4)
    startIndex  = 9 - start at the 9th image
    count       = 7 - display 7 images on this page (out of the total 15 images, there are only seven images left)
    columnCount = 4 - this is the number of columns in the table that is created

*/
function MakeTable(startIndex, count, columnCount) {
    var tblStart = "<table border=\"0\" class=\"photos\">";
    var tblEnd = "</table>";
    var tableRow = "";
    var n = 1;
    var newIndex = startIndex - 1;

    for (var i = newIndex; i < (newIndex + count); i++) {
        if ((i % columnCount) == 0) {
            tableRow += "<tr>";
        }

        tableRow += "<td align=\"center\"><a href=\"javascript:PopupPic(\'" + _imgPath + imageItems[i] + ".jpg\');\"><img border='0' src='../images/photos/clients/small/" + imageItems[i] + ".jpg' alt='" + RemoveUnderscores(imageItems[i]) + "' /></a>"
        tableRow += "</td>";

        if (n == columnCount) {
            tableRow += "</tr>";
            n = 1;
        } else {
            n++;
        }
    }
    return tblStart + tableRow + tblEnd;
}

function LoadTable() {
    var div = document.getElementById("photoGallery");
    div.innerHTML = MakeTable();
    alert(MakeTable());
}

function GetLargeImage() {
    var w = "700";
    var h = "297";
    
    var imgDiv = document.getElementById("imgPlaceHolder");
    var divCaption = document.getElementById("divCaption");
    if (_imgName != "") {
        divCaption.innerHTML = RemoveUnderscores(_imgName.toString());
        imgDiv.innerHTML = "<img src=\"..images/" + _imgName + ".jpg\" width=\"" + w + "\" height=\"" + h + "\" alt=\"" + RemoveUnderscores(_imgName) + "\" border=\"0\">";
    }
}

function PopupPic(sPicURL) {
    window.open("popup.html?" + sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200");
}

