// Javascript to popup an image in a new window

var newWindow = null;

var IP_WIDTH = 400;
var IP_HEIGHT = 400;

function openWindow(url, windowName, imageSrc) 
{
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        // ie
        var dim = 'scrollbars=no,resizable=yes,directories=no,location=no,menubar=no,status=no,toolbar=no,height=' + IP_HEIGHT + ',width=' + IP_WIDTH;
        newWindow = window.open("","_new",dim);
    }
    else
    {
        // firefox and all others
        var dim = 'scrollbars=no,resizable=yes,directories=no,location=no,menubar=no,status=no,toolbar=no,height=' + IP_HEIGHT + ',width=' + IP_WIDTH + ',screenX=' + (screen.availWidth/2 - IP_WIDTH) + ',screenY=' + (screen.availHeight/2 - IP_HEIGHT);
        newWindow = window.open(url, windowName, dim);
    }   
    
    if (newWindow == null)
    {
        // Popups are probably blocked so just forward to the image
        window.location.href = imageSrc;
        return;
    }
    
    newWindow.document.writeln('<html><head><title></title>'
        + '<link rel="stylesheet" type="text/css" href="css/style.css" />'
        + '<script src="scripts/vvvimagepopup2.js" type="text/javascript"></script>'
        + '</head>'
        + '<body style="margin:0;padding:0;" onload="resizeToFitImage();centreWindow();">'
        + '<h3 style="font-family: Sans-serif, Arial, Verdana, Geneva, Helvetica; text-align: center;">' 
        + windowName 
        + '</h3><img src="' + imageSrc 
        + '" style="margin:0;padding:0;" border="0" name="zoomImage"/><br/><a href="javascript:window.close();" style="float: right;">Close [X]</a></body></html>');

    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        // ie has a bug which means you need to delay a bit for the document to finish writing before you can close it.
        setTimeout('newWindow.document.close();', 2500);
        setTimeout('newWindow.focus();',3000);
    }   
    else
    {
        // firefox or other
        newWindow.document.close();
        newWindow.focus()
    }
}


function closeWindow() 
{
    if (newWindow != null) 
    {
        newWindow.close();
        newWindow = null;
    }
}

function resizeToFitImage()
{
    if (document.images['zoomImage'])
    {
        window.resizeTo(document.images['zoomImage'].width,document.images['zoomImage'].height + 130);
    }
    else
    {
        window.resizeTo(document.images[0].width,document.images[0].height + 130);
    }
}

function centreWindow()
{
    if (screen || screen.availWidth > 0)
    {
        w = screen.availWidth;
        h = screen.availHeight;
    }
    else if (document.body.clientWidth > 0 || document && document.all) 
    { 
        w = document.body.clientWidth; 
        h = document.body.clientHeight; 
    }
    else if (window) 
    { 
        w = window.innerWidth; 
        h = window.innerHeight; 
    }
    
    if (window.moveTo)
    {
        newx = Math.round((w/2) - (document.images[0].width / 2));
        newy = Math.round((h/2) - (document.images[0].height/2));        
        window.moveTo(newx,newy);
    }
}

function rollover(img_name, img_src)
{
    if (document.images)
    {
        img = document.images[img_name];
    }
    else if (document[img_name])
    {
        img = document[img_name];
    }
    else if (document.getElementByTagName(img_name))
    {
        img = document.getElementByTagName(img_name);
    }
    img.src = img_src;
}
