/*
Class: window
	Cross browser methods to get various window dimensions.
	Warning: All these methods require that the browser operates in strict mode, not quirks mode.
*/

window.extend({

	/*
	Property: getWidth
		Returns an integer representing the width of the browser window (without the scrollbar).
	*/

	getWidth: function(){
		//if (this.khtml) return this.innerWidth;
		//if (this.opera) return document.body.clientWidth;
		var width = -1;

		if (document.documentElement && document.documentElement.clientWidth)
		{
			width = document.documentElement.clientWidth;
		}
		if (document.body && document.body.clientWidth)
		{
			if(width>0)
				width = Math.min(document.body.clientWidth, width);
			else
				width = document.body.clientWidth;
		}

		return width;
	},

	/*
	Property: getHeight
		Returns an integer representing the height of the browser window (without the scrollbar).
	*/

	getHeight: function(){
		//if (this.khtml) return this.innerHeight;
		//if (this.opera) return document.body.clientHeight;
		var height = -1;

		if (document.documentElement && document.documentElement.clientHeight)
			height = document.documentElement.clientHeight;
		if (document.body && document.body.clientHeight)
		{
			if(height>0)
				height = Math.min(document.body.clientHeight, height);
			else
				height = document.body.clientHeight;
		}

		return height;
	},

	/*
	Property: getScrollWidth
		Returns an integer representing the scrollWidth of the window.
		This value is equal to or bigger than <getWidth>.

	See Also:
		<http://developer.mozilla.org/en/docs/DOM:element.scrollWidth>
	*/

	getScrollWidth: function(){
		//if (this.ie) return Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
		if (this.khtml) return document.body.scrollWidth;

		if (document.documentElement && document.documentElement.scrollWidth)
		{
			if(document.body)
				return Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
			return document.documentElement.scrollWidth;
		}
		else if (document.body)
			return document.body.scrollWidth;
		else
			return -1;
	},

	/*
	Property: getScrollHeight
		Returns an integer representing the scrollHeight of the window.
		This value is equal to or bigger than <getHeight>.

	See Also:
		<http://developer.mozilla.org/en/docs/DOM:element.scrollHeight>
	*/

	getScrollHeight: function()
	{
		//if (this.ie) return Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
		if (this.khtml) return document.body.scrollHeight;

		if (document.documentElement && document.documentElement.scrollHeight)
		{
			if (document.body)
				return Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
			else
				return document.documentElement.scrollHeight;
		}
		else if (document.body)
			return document.body.scrollHeight;
		else
			return -1;
	},

	/*
	Property: getScrollLeft
		Returns an integer representing the scrollLeft of the window (the number of pixels the window has scrolled from the left).

	See Also:
		<http://developer.mozilla.org/en/docs/DOM:element.scrollLeft>
	*/

	getScrollLeft: function()
	{
		if(this.pageXOffset)
			return this.pageXOffset;
		else if(document.documentElement && document.documentElement.scrollLeft)
			return document.documentElement.scrollLeft;
		else if(document.body)
			return document.body.scrollLeft;
		else
			return -1;
	},

	/*
	Property: getScrollTop
		Returns an integer representing the scrollTop of the window (the number of pixels the window has scrolled from the top).

	See Also:
		<http://developer.mozilla.org/en/docs/DOM:element.scrollTop>
	*/

	getScrollTop: function()
	{
		if(this.pageYOffset)
			return this.pageYOffset;
		else if(document.documentElement && document.documentElement.scrollTop)
			return document.documentElement.scrollTop;
		else if(document.body)
			return document.body.scrollTop;
		else
			return -1;
	},

	/*
	Property: getSize
		Same as <Element.getSize>
	*/

	getSize: function(){
		return {
			'size': {'x': this.getWidth(), 'y': this.getHeight()},
			'scrollSize': {'x': this.getScrollWidth(), 'y': this.getScrollHeight()},
			'scroll': {'x': this.getScrollLeft(), 'y': this.getScrollTop()}
		};
	},

	//ignore
	getPosition: function(){return {'x': 0, 'y': 0}}

});
