﻿var albums = new Array();

function init() {
    parseXML();
    listAlbums();
}

function parseXML() {
    try //Internet Explorer
  {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    catch (e) {
        try //Firefox, Mozilla, Opera, etc.
    {
            xmlDoc = document.implementation.createDocument("", "", null);
        }
        catch (e) {
            alert(e.message);
            return;
        }
    }
    xmlDoc.async = false;
    xmlDoc.load("photos.xml");

    var albumsXML = xmlDoc.selectNodes('/Charndon/Album');

    for (i = 0; i < albumsXML.length; i++) {
        var photosXML = albumsXML[i].childNodes;
        albums[i] = new Array();
        for (j = 0; j < photosXML.length; j++) {
            albums[i][j] = photosXML[j].text;
        }
    }
}

function listAlbums() 
{
    var html = "";
    for (var i = 0; i < albums.length; i++) 
    {
        html+= "<div onclick='selectAlbum(" + i + ")' class='albumLink'>" + albums[i][0] + "</div>";
    }
    document.getElementById("albums").innerHTML=html;
}


function selectAlbum(albumID) {
    var html = "";
    for (var i = 1; i < albums[albumID].length; i++) {
        html += "<img alt='Photo " + i + "' src='" + albums[albumID][i] + "' onclick='selectPhoto(" + albumID + ", " + i + ")' class='photoLink' />";
    }
    document.getElementById("photos").innerHTML = html;
}

function selectPhoto(albumID, photoID) {
    document.getElementById("photoImage").src = albums[albumID][photoID];
    document.getElementById("photoImage").style.width=null;
    }

function openPhoto() {
    window.open(document.getElementById("photoImage").src);
}