function loadImage()
{
 var himg = new Array('./images/main5.jpg','./images/main6.jpg','./images/main7.jpg');
 var next_image = (read_cookie('next_image') || 0)%himg.length;
 write_cookie('next_image',next_image+1);
 var nimg = himg[next_image];
 setBackgroundImage('mainImage',nimg);
}

function read_cookie(name)
{
        var stop,index;

        index = document.cookie.indexOf(name + "=");
        if (index == -1) return (0);
        index = document.cookie.indexOf("=", index) + 1;
        stop = document.cookie.indexOf(";", index);
        if (stop == -1) stop = document.cookie.length;
        return(unescape(document.cookie.substring(index, stop)));
}
function write_cookie(name,value)
{
        var cookie = name + "=" + value + ";";
        document.cookie = cookie;
}

function setBackgroundImage (id, imageURL)
{
        if (document.layers)
                document[id].background.src = imageURL == 'none' ? null : imageURL;
        else if (document.all)
                document.all[id].style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
        else if (document.getElementById)
                document.getElementById(id).style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
}
