﻿// variables
var PhotosPath = "http://core.braveheartwomen.com/content/splash_photos";
var PhotosXML = "http://core.braveheartwomen.com/content/splash_photos/photos.xml";

// onload event
window.onload = function() {
    RandomPhotos();
    SetupForm();
}

// display random photos
function RandomPhotos() {
    var a = new Array(photos.length);
    var tbl = obj("Layout");

    for (var i = 0; i < photos.length; i++) { a[i] = i; }
    shuffle(a);

    for (var i = 0; i < 10; i = i + 2) {
        tbl.rows[0].cells[0].innerHTML += GeneratePhotoHTML(photos[a[i]]);
        tbl.rows[0].cells[2].innerHTML += GeneratePhotoHTML(photos[a[i + 1]]);
    }

    /*LoadXML(PhotosXML, function() {
        if (request.readyState == 4) {
            if (request.status == 200) {
                var xmlDoc = request.responseXML;
                var photos = xmlDoc.getElementsByTagName("photo")
                var a = new Array(photos.length);
                var tbl = obj("Layout");

                for (var i = 0; i < photos.length; i++) { a[i] = i; }
                shuffle(a);

                for (var i = 0; i < 10; i = i + 2) {
                    tbl.rows[0].cells[0].innerHTML += GeneratePhotoHTML(photos[a[i]]);
                    tbl.rows[0].cells[2].innerHTML += GeneratePhotoHTML(photos[a[i + 1]]);
                }
            } else {
                //alert("There was a problem retrieving the XML data");
            }
        }
    });*/
}

// generate HTML for random photo
function GeneratePhotoHTML(photo) {
    var nm = photo.name;
    var loc = photo.location;
    var src = PhotosPath + "/" + photo.filename;
    var htm = "";

    // add photo, frame and caption
    htm += "<img alt=\"\" class=\"photo\" height=\"82\" src=\"" + src + "\" width=\"111\" />";
    htm += "<div class=\"frame\"></div>";
    htm += "<div class=\"caption\">" + nm + (loc.length > 1 ? (" - " + loc) : "") + "</div>"; 

    return "<div class=\"splashPhoto\">" + htm + "</div>";
}
