// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page
var xMousePosMin = 0; // Width of the page
var yMousePosMin = 0; // Height of the page

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
  
function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
function PopUpMessage(anchor,message)
	{
    if (document.layers) {
        xMousePosMin = window.pageXOffset;
        yMousePosMin = window.pageYOffset;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        xMousePosMin = document.body.scrollLeft;
        yMousePosMin = document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePosMin = window.pageXOffset;
        yMousePosMin = window.pageYOffset;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
	
	CurrentFloater = anchor;
	document.getElementById('FloaterWindowMessageSpan').innerHTML = '<img src=' + message + '>';
	PosX = findPosX(document.getElementById(anchor));
	PosY = findPosY(document.getElementById(anchor));
	//FloaterWidth  = document.getElementById('FloaterWindowTable').offsetWidth;
	//FloaterHeight = document.getElementById('FloaterWindowTable').offsetHeight;

	FloaterWidth  = 800;
	FloaterHeight = 640;
	linkWidth  = document.getElementById(anchor).offsetWidth;
	linkHeight = document.getElementById(anchor).offsetHeight;
	//alert(PosY + ' : ' + FloaterHeight + ' : ' + linkWidth + ' : ' + yMousePosMax + ' : ' + yMousePosMin);
	if (PosX + FloaterWidth + 25 > xMousePosMax) // OPEN ON THE LEFT
		{document.getElementById('FloaterWindow').style.left = 5}
	else	
		{document.getElementById('FloaterWindow').style.left = PosX;}
		
	if (PosY - FloaterHeight + 25 < yMousePosMin)
		{document.getElementById('FloaterWindow').style.top = yMousePosMin + 5;}
	else if (PosY + FloaterHeight > yMousePosMax)
		{document.getElementById('FloaterWindow').style.top = yMousePosMax - FloaterHeight - 50;}
	else
		{document.getElementById('FloaterWindow').style.top = PosY - FloaterHeight + 25;}
	document.getElementById('FloaterWindow').style.visibility = 'visible'
	}

function HideFloaterWindow()
	{
	if (CurrentFloater != "TellFriend")
		{document.getElementById('FloaterWindow').style.visibility = 'hidden';}
	}

