// Get functions reformated, but originally curtesy of http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
// Information from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
//	and just plain testing....
// also used to modify the results of GetClientWidth and GetClientHeight, because netscape and firefox
// include the scrollbar size in the returned values
// NOTE: This code REQUIRES the following line at the top of your html files.
//		<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
// Unfortunately, removing that or using different doctypes gives different results, and I do not know how to test
// what doctype a particular html file was written with
//
// At the time of finding the original code at http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
// there were no restrictions on redistribution, and it was apparently posted into public domain.
// As for my modifications, I also post them to the public domain and you can use or abuse this script as you please
// I am providing this script on an "as is" basis, and make no warranties regarding it or its capabilities.
// I disclaim any liability for damages resulting from its use.
//	-- John Postmus

function GetScrollX()
{
  var scrOfX = 0;
  if(typeof( window.pageYOffset ) == 'number')
  {
    //Netscape compliant
    scrOfX = window.pageXOffset;
  }
  else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
  {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  }
  else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
  {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
 
  return scrOfX;
}

function GetScrollY()
{
  var scrOfY = 0;
  if(typeof( window.pageYOffset ) == 'number')
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  }
  else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  }
  else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
 
  return scrOfY;
}

function GetClientWidth()
{
	var myWidth = 0;
	if(typeof( window.innerWidth ) == 'number')
	{
		//Non-IE
		myWidth = window.innerWidth;

		// Firefox and Netscape hack (to remove scrollbar inclusion)
		if((navigator.appName.indexOf("Netscape")!=-1) && (document.documentElement))
			myWidth = document.documentElement.clientWidth;

		// Opera hack (to remove scrollbar inclusion)
		if((navigator.appName.indexOf("Opera")!=-1) && (document.body))
			myWidth = document.body.clientWidth;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}

	return myWidth;
}

function GetClientHeight()
{
	var myHeight = 0;

	if(typeof( window.innerWidth ) == 'number')
	{
		//Non-IE
		myHeight = window.innerHeight;

		// Firefox and Netscape hack (to remove scrollbar inclusion)
		if((navigator.appName.indexOf("Netscape")!=-1) && (document.documentElement))
			myHeight = document.documentElement.clientHeight;

		// Opera hack (to remove scrollbar inclusion)
		if((navigator.appName.indexOf("Opera")!=-1) && (document.body))
			myHeight = document.body.clientHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	
	return myHeight;
}

function FloatObj(id, x, y)
{
	// Some browsers, such as Netscape 4, don't take a px at the end of a location those
	// browsers also do not have a document.layers attribute so, we determine
	// which it is now, and later we just append the px variable regardless
	var px=document.layers?'':'px';

	// If the client supports getElementById, then use it
	var Obj;
	if(document.getElementById)
		Obj = document.getElementById(id);
	// If the client does NOT support getElementById, try the alternatives
	else
	{
		// If the client supports document.all, then use it
		if(document.all)
			Obj = document.all[id];
		// If the client does NOT support document.all, then user our last option...
		else
			Obj = document.layers[id];
	}
	
	// The browsers which do not support layers, do not have an inherent style attrib
	// so setup a simulated one to point to the object itself
	if(document.layers)
		Obj.style=Obj;

	// Determine the page width, page height, x and y scroll locations
	var w, h, sx, sy;
	w = GetClientWidth();
	h = GetClientHeight();
	sx = GetScrollX();
	sy = GetScrollY();

	// Set the object position finally
	if(x > 0)	// A positive direction is easy, just add the scroll position
		Obj.style.left = sx + x + px;
	else			// A negative direction requires taking the client page size into account
		Obj.style.left = w + x + sx + px;

	if(y > 0)	// A positive direction is easy, just add the scroll position
		Obj.style.top = sy + y + px;
	else			// A negative direction requires taking the client page size into account
		Obj.style.top = h + y + sy + px;

	// Make sure FloatObj is called frequently, to move the object
	setTimeout("FloatObj('"+id+"', "+x+", "+y+")", 33);
}
