
// register the function that's going to set up the links
window.onload = prepareGallery;

function prepareGallery() {
    // Check everything we need works
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById) return false;
    if (!document.getElementById("thumbnails")) return false;
    // find the gallery
    var gallery = document.getElementById("thumbnails");
    // find all the links in the gallery
    var links = gallery.getElementsByTagName("a");
    // set up the function on each link
    for (var i=0; i<links.length; i++){
        links[i].onclick = function() {
            return showPic(this);
        }
    }
}

function showPic(whichpic) {
    // check the placeholder exists
    if (!document.getElementById("placeholder")) return true;
    // find the source to use
    var source = whichpic.getAttribute("href");
    // find the placeholder
    var placeholder= document.getElementById("placeholder");
    // check the placeholder is an image
    if (placeholder.nodeName != "IMG") return true;
    // change the source
    placeholder.setAttribute("src", source);
    
    
    // now set up the title. Get the title of the link and use that
    //var text = whichpic.getAttribute("title") ? whichpic.getAttribute("title") : "undefined";
    //alert(text);

    //var title = document.getElementById("gallerytitle");
    //alert(title.firstChild.nodeVaue);
    //title.firstChild.nodeVaue = text;
    
    // Return false so we don't follow the link to the picture
    return false;
    
}

