// Move the info object relative to cig object.
function move_info(cig, info)
{
    var cleft = -302;
    var ctop = -44;
    var obj = cig;

    while (obj.offsetParent)
    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

    info.style.left = cleft + 'px';

    ctop += cig.offsetHeight + 0;

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    info.style.top = ctop + 'px';
}

// Show info if it wasn't shown yet or is hidden
// or hide it if it is currently shown
function pop_info(cig, width, height, borderStyle)
{
    var href = cig.href;
    var infodiv = document.getElementById(href);

    if (infodiv != null)
    {
        if (infodiv.style.display=='none')
        {
            // Show existing info, move it
            // if document changed layout
            move_info(cig, infodiv);
            infodiv.style.display='block';
        }
        else
            // Hide currently shown info.
            infodiv.style.display='none';
        return false;
    }

    // Create info object through DOM
    infodiv = document.createElement('div');

    // Assign id equal to the document it will show
    infodiv.setAttribute('id', href);

    infodiv.style.display = 'block';
    infodiv.style.position = 'absolute';
    infodiv.style.width = width + 'px';
    infodiv.style.height = height + 'px';
    infodiv.style.border = borderStyle;
    infodiv.style.textAlign = 'right';
    infodiv.style.padding = '0px';
    infodiv.style.background = '#000000';
    document.body.appendChild(infodiv);

    var offset = 0;

    var contents = document.createElement('iframe');
    contents.scrolling = 'no';
    contents.overflowX = 'hidden';
    contents.overflowY = 'hidden';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    infodiv.appendChild(contents);

    move_info(cig, infodiv);

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href);
    else
        contents.src = href;

    // The script has successfully shown the info,
    // prevent hyperlink navigation.
    return false;
}
