// image helper code
// Copyright (c) Object Media Limited 2006

/* disable hyperlinks surrounding images when the page loads */

function init()
{
    disableHyperLinks();

    var text;

    text = document.getElementById("test");
    if (text != null)
    {
        text.style.display = "none";                // comment out for debugging
        text.innerHTML = "test oninit";
    }
}

/* This disables all hyperlinks with the id "disableLink".
   These hyperlinks are also set with an onmouseover function which is passed the
   link when called. That function's job is to change the image in the center of the screen
*/

function disableHyperLinks()
{
    var links = document.links;

    for(i = 0; i < links.length; i++)
    {
        if (links[i].id == "disableLink")
        {
            //links[i].href = null;
            links[i].onmouseover = setNewImage;
            links[i].onclick = setNewImage;
        }
    }
}

/* This function uses the passed in link (<A>) to determine the image inside the link.
   It then gets the image name, removes the "small" directory prefix and sets the new URL
   as the main image on the page
*/

function setNewImage()
{
    var link = this;
    var image;
    var newImageURL, url;
    var index;

    // get the image inside the link

    image = link.childNodes[0];
    if (image != null)
    {
        // get the image URL from the image

        url = image.src;
        if (url != null)
        {
            // remove the /small/ from the image URL

            index = url.indexOf("/small/");
            if (index != -1)
            {
                newImageUrl = url.substr(0, index + 1);
                newImageUrl += url.slice(index + 7, url.length);
            }
            else
            {
                newImageURL = url;
            }
        }
    }
    else
    {
        newImageURL = "no child image";
    }

    // set the image to display

    image = document.getElementById("mainImage");
    if (image != null)
    {
        image.src = newImageUrl;
    }

    var text;

    text = document.getElementById("test");
    if (text != null)
    {
        text.innerHTML = newImageUrl;
    }

    // return false to prevent the hyperlink from being taken when user clicks it

    return false;
}
