var windowSupport=
{
	ih:									0,	// Interstitial height of the window
	iw:									0,	// Interstitial width of the window
	
	// Find the interstitial sizes of the window. These are defined as the
	// differences in dimensions of the window itself, and the document area.
	// Because Internet Explorer doesn't support outerHeight and outerWidth,
	// we can do this by resizing the window to a knows size, reading its
	// inner dimensions and subtracting them from the known window size. Once
	// we have these values, we can put the window back to its original size.
	getInterstitial: function()
	{
		var fs=400;
		var h=this.innerHeight();
		var w=this.innerWidth();
		var x=window;
		this.setOuterSize(fs,fs);
		this.ih=fs-this.innerHeight();
		this.iw=fs-this.innerWidth();
		this.setOuterSize(w+this.iw, h+this.ih);
	},

	// return document.all
	getAll: function()
	{
		return document.all ? document.all : document.getElementsByTagName("*");
	},

  // return the absolute TOP of something
  getElementTop: function(elem)
	{
		var yPos = elem.offsetTop;
		var tempEl = elem.offsetParent;
		while (tempEl)
		{
			yPos += tempEl.offsetTop-(tempEl.scrollTop? tempEl.scrollTop : 0);
			tempEl = tempEl.offsetParent;
		}
		return yPos-0;
	},

  // Return the absolute LEFT of something.
  getElementLeft: function(elem) 
	{
		var xPos = elem.offsetLeft;
		var tempEl = elem.offsetParent;
		while (tempEl)
		{
			xPos += tempEl.offsetLeft-(tempEl.scrollLeft? tempEl.scrollLeft : 0);
			tempEl = tempEl.offsetParent;
		}
		return xPos-0;
	},

	// State whether an element is a primal one, i.e. it doesn't exist inside
	// a DIV or a TABLE, or something like that.
	isPrimal: function(elem)
	{
		var p=true;
		var ep=elem.offsetParent;
		while (ep && p)
		{
			var x="|"+ep.tagName.toLowerCase()+"|";
			if ("|div|iframe|table|select|td|tr|".indexOf(x)>=0)
			{
				p=false;}
			ep=ep.offsetParent;
		}
		return p;
	},

	// find the lowest occupied point in the document
	lowestPoint: function()
	{
		var lp=0;
		var x=this.getAll();
		for (var i=0; i<x.length; i++)
		{
			var y=x[i];
			if ((y.tagName) && (y.offsetHeight) && this.isPrimal(y))
			{
				var tn="|"+y.tagName.toLowerCase()+"|";
				if ("|html|body|head|form|script|".indexOf(tn)<0)
				{
					var w=this.getElementTop(y)+y.offsetHeight;
					if (y.scrollHeight)
						w=this.getElementTop(y)+y.scrollHeight;
					if (w>lp)
						lp=w;
				}
			}
		}
		return lp-0;
	},

	// find the rightmost occupied point in the document
	rightmostPoint: function()
	{
		var rp=0;
		var x=this.getAll();
		for (var i=0; i<x.length; i++)
		{
			var y=x[i];
			if ((y.tagName) && (y.offsetWidth) && this.isPrimal(y))
			{
				var tn="|"+y.tagName.toLowerCase()+"|";
				if ("|html|body|head|form|script|".indexOf(tn)<0)
				{
					var w=this.getElementLeft(y)+y.offsetWidth;
					if (w.scrollWidth)
						var w=this.getElementLeft(y)+y.scrollWidth;
					if (w>rp)
						rp=w;
				}
			}
		}
		return rp-0;
	},

	// Get the width of the browser window
	outerWidth: function()
	{
		if (window.outerWidth)
			return window.outerWidth;
		else
		{
			if (this.iw==0)
				this.getInterstitial();
			return this.innerWidth()+this.iw;
		}
	},

	// Get the height of the browser window
	outerHeight: function()
	{
		if (window.outerHeight)
			return window.outerHeight;
		else
		{
			if (this.ih==0)
				this.getInterstitial();
			return this.innerHeight()+this.ih;
		}
	},

	// This returns the inner width of the current Window
	innerWidth: function()
	{
		if (window.innerWidth)
			return window.innerWidth;
		else if (document.body)
			return document.body.clientWidth;
		else if (document.documentElement && document.documentElement.clientWidth)
			return document.documentElement.clientWidth;
		else
			return screen.width;
	},

	// This returns the inner height of the current Window
	innerHeight: function()
	{
		if (window.innerWidth)
			return window.innerHeight;
		else if (document.body)
			return document.body.clientHeight;
		else if (document.documentElement && document.documentElement.clientWidth)
			return document.documentElement.clientHeight;
		else
			return screen.height;
	},

	// This returns the interstitial width of the window
	interstitialWidth: function()
	{
		return this.outerWidth()-this.innerWidth();
	},
	
	// This returns the interstitial height of the window
	interstitialHeight: function()
	{
		return this.outerHeight()-this.innerHeight();
	},

	// This sets the innerWidth of the window
	setInnerWidth: function(newWidth)
	{
		if (self.innerWidth)
		{
			var x=window;
			x.innerWidth=newWidth;
		}
		else
			this.setOuterWidth(newWidth+this.interstitialWidth());
	},

	// This sets the innerHeight of the window
	setInnerHeight: function(newHeight)
	{
		if (self.innerWidth)
		{
			var x=window;
			x.innerHeight=newHeight;
		}
		else
			this.setOuterHeight(newHeight+this.interstitialHeight());
	},

	// This changes the width of the window
	setOuterWidth: function(newWidth)
	{
		this.setOuterSize(newWidth, this.getOuterHeight());
	},

	// This changes the height of the window
	setOuterHeight: function(newHeight)
	{
		this.setOuterSize(this.getOuterWidth(), newHeight);
	},

	setInnerSize: function(newWidth, newHeight)
	{
		if (this.ih==0)
			this.getInterstitial();
		this.setOuterSize(newWidth+this.iw, newHeight+this.ih);
	},

	setOuterSize: function(newWidth, newHeight)
	{
		var x=window;
		x.resizeTo(newWidth, newHeight);
	},

	fitToContents: function()
	{
		var hm=20;
		var wm=20;
		if (document.body.topMargin)
			hm=(document.body.topMargin-0)*2;
		if (document.body.leftMargin)
			wm=(document.body.leftMargin-0)*2;
		var h=this.lowestPoint();
		var w=this.rightmostPoint();
		this.setInnerSize(w+wm, h+hm);
	},
	
	center: function()
	{
		var left=(screen.width-this.outerWidth())/2;
		var top=(screen.height-this.outerHeight())/2;
		self.moveTo(left,top);
	},
	
	fitAndCenter: function()
	{
		this.fitToContents();
		this.center();
	}
};
