function init()
{
    Images.update();
    Links.update();
}

var Images = {
    update: function()
    {
        var images = document.getElementsByTagName('img');
        for (var i = 0; i < images.length; i++)
        {
            var im = images[i];
            if ((im.id.substring(0, 6) == 'popup-') || 
                (im.className == 'popup'))
            {
                im.onclick = function() {Images.popup(this);};
                im.className += ' popup';
            }
        }
    },
    popup: function(image)
    {
        var src = image.src;
        if (src.indexOf('?') >= 0)
            src = src.substring(0, src.indexOf('?'));
        var src = '/fullimage?src=' + src;
        var win = window.open(src, 'impopup', 'toolbar=0,location=0,' +
            'statusbar=0,menubar=0,resizable=1,' +
            'width=' + 1 + ',' +
            'height=' + 1);
    },
    resize_to_fit: function()
    {
        var image = document.images[0];
        var IE = (navigator.appName.indexOf("Microsoft") != -1);
        var width = (IE) ? document.documentElement.clientWidth : window.innerWidth;
        var height = (IE) ? document.documentElement.clientHeight : window.innerHeight;
        window.resizeBy(image.width - width, image.height - height);
    }
}

var Links = {
    update: function()
    {
        var links = document.getElementsByTagName('a');
        for (var i = 0; i < links.length; i++)
        {
            var ln = links[i];
            if (ln.target == 'popup')
            {
                ln.onclick = function() {return Links.popup(this);};
            }
        }
    },
    popup: function(link)
    {
        var src = '/fullimage?src=' + link.href;
        var win = window.open(src, 'impopup', 'toolbar=0,location=0,' +
            'statusbar=0,menubar=0,resizable=1,' +
            'width=' + 1 + ',' + 'height=' + 1);
        return false;
    }
}

function popup(src, properties)
{
    if (properties == undefined)
        properties = 'toolbar=0,location=0,statusbar=0,menubar=0,resizable=1' +
            ',width=800,height=600';
    window.open(src, 'popup', properties);
}

function redraw_menu_title()
{
    var title = document.getElementById('menu-title');
    var display = title.style.display;
    title.style.display = 'none';
    title.style.display = display;
}
