/*
Script: Window.Size.js
        Window cross-browser dimensions methods.

Note:
        The Functions in this script require an XHTML doctype.

License:
        MIT-style license.
*/

/*
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.webkit419) return this.innerWidth;
                if (this.opera) return document.body.clientWidth;
                return document.documentElement.clientWidth;
        },

        /*
        Property: getHeight
                Returns an integer representing the height of the browser window (without the scrollbar).
        */

        getHeight: function(){
                if (this.webkit419) return this.innerHeight;
                if (this.opera) return document.body.clientHeight;
                return document.documentElement.clientHeight;
        },

        /*
        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.webkit) return document.body.scrollWidth;
                return document.documentElement.scrollWidth;
        },

        /*
        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.webkit) return document.body.scrollHeight;
                return document.documentElement.scrollHeight;
        },

        /*
        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(){
                return this.pageXOffset || document.documentElement.scrollLeft;
        },

        /*
        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(){
                return this.pageYOffset || document.documentElement.scrollTop;
        },

        /*
        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};},

        getPageSize: function()
        {
           var xScroll, yScroll;
           if (window.innerHeight && window.scrollMaxY)
           {
              xScroll = document.body.scrollWidth;
              yScroll = window.innerHeight + window.scrollMaxY;
           }
           else if (document.body.scrollHeight > document.body.offsetHeight)
           {
              xScroll = document.body.scrollWidth;
              yScroll = document.body.scrollHeight;
           }
           else
           {
              xScroll = document.body.offsetWidth;
              yScroll = document.body.offsetHeight;
           }
           var windowWidth, windowHeight;
           if (self.innerHeight)
           {
              windowWidth = self.innerWidth;
              windowHeight = self.innerHeight;
           }
           else if (document.documentElement && document.documentElement.clientHeight)
           {
              windowWidth = document.documentElement.clientWidth;
              windowHeight = document.documentElement.clientHeight;
           }
           else if(document.body)
           {
              windowWidth = document.body.clientWidth;
              windowHeight = document.body.clientHeight;
           }
           pageHeight = Math.max(yScroll, windowHeight);
           pageWidth = Math.max(xScroll, windowHeight);
           return new Array(pageWidth, pageHeight, windowWidth, windowHeight);        }

});
