function beginSSPreview(pProjectId, pImageId)
{
    var fsc = $element('fullscreener');
    var prog = $element('progressdiv');
    var docsize = $.docSize();
    var cntr = $.viewCenter();
    fsc.setPos(0, 0).setSize(docsize.w, docsize.h, 'px').show();
    prog.setPos(cntr.x - 50, cntr.y - 9, 'px').show();
    var thecon = new IsisAjax();
    thecon.onEnd = ssDescriptionLoaded;
    var theurl = base_project_url + 'ops-getssparams-' + pProjectId + '-' + pImageId;
    thecon.getUrl(theurl);
}

function beginPicPreview(pImageId)
{
    var fsc = $element('fullscreener');
    var prog = $element('progressdiv');
    var docsize = $.docSize();
    var cntr = $.viewCenter();
    fsc.setPos(0, 0).setSize(docsize.w, docsize.h, 'px').show();
    prog.setPos(cntr.x - 50, cntr.y - 9, 'px').show();
    var thecon = new IsisAjax();
    thecon.onEnd = ssDescriptionLoaded;
    var theurl = base_project_url + 'ops-getpicparams-' + pImageId;
    thecon.getUrl(theurl);
}

function endPicPreview()
{
    $element('fullscreener').hide();
    $element('picpreviewbox').hide();
    $element('progressdiv').hide();
}

function ssDescriptionLoaded(pResult, pError, pErrorMsg)
{
    if (pError)
    {
        endPicPreview();
        return;
    }

    if (pResult == 'err')
    {
        endPicPreview();
        return;
    }

    var res = null;

    try
    {
        res = eval(pResult);
    }
    catch(err) { res = null; }

    if (!res)
    {
        endPicPreview();
        return;
    }

    if (res.w == 'err')
    {
        endPicPreview();
        return;
    }

    // Hide progress bar
    $element('progressdiv').hide();
    // Get view size and center
    var viewsize = $.viewSize();
    var cntr = $.viewCenter();
    // Estimate the size of the box
    var boxsizeest = {'w': res.w + 100, 'h': res.h + 130};

    if (boxsizeest.w < 500)
        boxsizeest.w = 500;

    // Estimate new box position
    var boxposest = {'x': 0, 'y:': 0};

    if (boxsizeest.h / 2 + 100 > viewsize.h / 2)
    {
        boxposest.x = cntr.x - Math.round(boxsizeest.w / 2);
        boxposest.y = cntr.y - Math.round(viewsize.h / 2);
    }
    else
    {
        boxposest.x = cntr.x - Math.round(boxsizeest.w / 2);
        boxposest.y = cntr.y - Math.round(boxsizeest.h / 2) - 100;
    }

    // Get the image container object
    var boximage = $element('picpreview_image');
    // Get the box object
    var box = $element('picpreviewbox');
    // Set image container size
    boximage.setSize(boxsizeest.w, boxsizeest.h - 95, 'px');
    // Set the image
    boximage.obj().innerHTML = res.imgtag;
    // Set the width of the preview box
    box.setSize(boxsizeest.w, null, 'px');
    // Set the position of the preview box
    box.setPos(boxposest.x, boxposest.y, 'px');
    // Set the title and description
    $element('picpreview_title').obj().innerHTML = res.ttl;
    $element('picpreview_description').obj().innerHTML = res.desc;
    // Show the box
    box.show();

    // Resize fullscreener
    var docsz = $.docSize();
    $element('fullscreener').setSize(null, docsz.h, 'px');
}


function hideIeWarning()
{
    alert('%%msg_iewarnhiding%%');
    location.href='ops-hideiewarning';
}
