
WindowOnload(loadPeopleTable);

function loadPeopleTable() {
    /* find the anchor */
    var people = document.getElementById('people');
    if (!people) {
        throw "Don't know where to list peoples!";
    }

    /* erase the note */
    while (people.firstChild) {
          people.removeChild(people.firstChild);
    }

    /* set up the table */
    var table = document.createElement('table');
    var header = table.createTHead().insertRow(-1);
    var idLabel = document.createElement('th');
    /* empty */
    header.appendChild(idLabel);

    var nameLabel = document.createElement('th');
    nameLabel.appendChild(document.createTextNode('Name'));
    header.appendChild(nameLabel);

    var contactLabel = document.createElement('th');
    contactLabel.appendChild(document.createTextNode('Contact'));
    header.appendChild(contactLabel);

    var introLabel = document.createElement('th');
    introLabel.appendChild(document.createTextNode('Flash Introduction'));
    header.appendChild(introLabel);

    /* insert people info */
    var body = document.createElement('tbody');
    table.appendChild(body);

    var peoplelength = people.getAttribute("length");
    var peoplesrc = people.getAttribute("src");
    for (var i = 0; i < peoplelength; i++) {
        var id = (i + 10000).toString();
        id = id.slice(1);

        var row = body.insertRow(-1);
        var idString = document.createTextNode(i);
        row.insertCell(-1).appendChild(idString);

        var nameImg = document.createElement('img');
        nameImg.src = peoplesrc + "/" + id + "/name.png";
        row.insertCell(-1).appendChild(nameImg);

        var addrImg = document.createElement('img');
        addrImg.src = peoplesrc + "/" + id + "/addr.png";
        row.insertCell(-1).appendChild(addrImg);

        var introLink = document.createElement('a');
        introLink.href = peoplesrc + "/" + id + "/flash.html";
        introLink.appendChild(document.createTextNode("intro"));
        row.insertCell(-1).appendChild(introLink);
    }

    /* finally, attach the table */
    people.appendChild(table);
}


