//-----------------------------------------------------------------------
// Copyright 2005, VTAS Automation Services
//-----------------------------------------------------------------------
// File       : thumb.js
// Description: Displaying thumbnails (Javascript)
//-----------------------------------------------------------------------
// History    :
//  nov05,acv   Initial version
//
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------

var startPosX = 0;
var startPosY = 0;
var thumbPosX = 0;
var thumbPosY = 0;

// Check for Netscape or Internet Explorer
var ns = (navigator.appName.indexOf("Netscape") != -1);
//alert( navigator.appName + " ==> ns: " + ns);

//-----------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------

function InitThumbPos( pX, pY )
{
    startPosX = pX;
    startPosY = pY;
}

function ShowThumb( pID )
{
    // Determine the ID of the thumbnail
    picSpanID = 'thumb_' + pID;

    // Determince the position of this thumbnail
    SetThumbPos( picSpanID );

    // Move thumbnail to its position and show
    if (document.all) 
    {
        document.all(picSpanID).style.left = thumbPosX;
        document.all(picSpanID).style.top = thumbPosY;
        document.all(picSpanID).style.visibility = 'visible';
    }
    else if (document.layers) 
    {
        document.layers[picSpanID].left = thumbPosX;
        document.layers[picSpanID].top = thumbPosY;
        document.layers[picSpanID].visibility = 'show';
    }
    else if (document.getElementById) 
    {
        document.getElementById(picSpanID).style.left = thumbPosX;
        document.getElementById(picSpanID).style.top = thumbPosY;
        document.getElementById(picSpanID).style.visibility = 'visible';
    }
}

function HideThumb( pID )
{
    // Determine the ID of the thumbnail
    picSpanID = 'thumb_' + pID;

    // Hide this thumbnail
    if (document.all) 
    {
         document.all(picSpanID).style.visibility = 'hidden';
    }
    else if (document.layers) 
    {
         document.layers[picSpanID].visibility = 'hide';
    }
    else if (document.getElementById) 
    {
        document.getElementById(picSpanID).style.visibility = 'hidden';
    }
}

function GetMouse() 
{
    var root = document.documentElement||document.body;
    var mouX = event.pageX || event.clientX + root.scrollLeft;
    var mouY = event.pageY || event.clientY + root.scrollTop;

    return { x: mouX, y: mouY };
}

function SetThumbPos( pID )
{
    // Get the position of the mouse
    m = GetMouse();

    // Determine the 'horizontal' position
    if (document.all) 
    {
         picWidth = document.all(pID).lastChild.width;
         picHeight = document.all(pID).lastChild.height;
    }
    else if (document.layers) 
    {
         picWidth = document.layers[pID].lastChild.width;
         picHeight = document.layers[pID].lastChild.height;
    }
    else if (document.getElementById) 
    {
        picWidth = document.getElementById(pID).lastChild.width;
        picHeight = document.getElementById(pID).lastChild.height;
    }
    thumbPosX = startPosX - picWidth;

    // Determine the 'vertical' position
    thumbPosY = m.y - picHeight;
    thumbPosY += ns ? pageYOffset : document.body.scrollTop;
    if( thumbPosY < startPosY )
    {
        thumbPosY = startPosY;
    }
}


