/* *** Returns the height of the viewport. *** */
function getViewportHeight()
{
    // supported in Mozilla, Opera, and Safari
     if(window.innerHeight)
         return window.innerHeight;
	
    // supported in standards mode of IE, but not in any other mode
     if(window.document.documentElement.clientHeight)
         return document.documentElement.clientHeight;
	
    // supported in quirks mode, older versions of IE, and mac IE (anything else).
    return window.document.body.clientHeight;
}	

/* *** Returns the height of the viewport. *** */
function getViewportWidth()
{
    // supported in Mozilla, Opera, and Safari
     if(window.innerWidth)
         return window.innerWidth;
	
    // supported in standards mode of IE, but not in any other mode
     if(window.document.documentElement.clientWidth)
         return document.documentElement.clientWidth;
	
    // supported in quirks mode, older versions of IE, and mac IE (anything else).
    return window.document.body.clientWidth;
}	

function getScrollXY()
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' )
	{	// Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else
	{
		if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{	// DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		}
		else
		{
			if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
			{	//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
		}
	}
	return [ scrOfX, scrOfY ];
}

function docRefresh()
{
	/* topLink attributes defined */
	var tlnkWidth	= 30;	// (pixels)
	var tlnkHeight	= 33;	// (pixels)
	var tlnkX		= 0;	// (%)
	var tlnkY		= 99;	// (%)
	var scrollBar	= 20;	// (pixels)
	var xPos		= 0;
	var yPos		= 0;
	
	var docheight = getViewportHeight();
	var docwidth = getViewportWidth();
	var xyPos = getScrollXY();

	/* If we haven't moved, do not display the toplink */
	if ( (xyPos[0] == xyPos[1]) != 0 )
	{
		if ( document.getElementById )
		{
			document.getElementById('topLink').style.visibility = "hidden";
		}
		else if ( document.all )
		{
			document.all['topLink'].style.visibility = "hidden";
		}
		else { return; }
	}
	else
	{
		if ( document.getElementById )
		{
			document.getElementById('topLink').style.visibility = "visible";
		}
		else if ( document.all )
		{
			document.all['topLink'].style.visibility = "visible";
		}
		else { return; }
	}
	
	/* Calculate the position of our 'TopLink' */
	xPos = ((docwidth - tlnkWidth - scrollBar) * (tlnkX/100)) + xyPos[0];
	yPos = ((docheight - tlnkWidth - scrollBar) * (tlnkY/100)) + xyPos[1];

	/* Apply the required offsets */
	if ( document.getElementById )
	{
		document.getElementById('topLink').style.left = xPos;
		document.getElementById('topLink').style.top = yPos;
	}
	else if ( document.all )
	{
		document.all['topLink'].style.left = xPos;
		document.all['topLink'].style.top = yPos;
	}
	else { return; }
}

function inttimer()
{
	docRefresh();
	window.onresize=docRefresh;
	docID = setInterval ("docRefresh()", 50);
}

