/**
 * @author Sebastian Romero April-03-2008
 * @projectDescription Utilities for Page
 * @version 1.0
 * @notes Put methods for page only
 */
var Page = {
    /*
     Gets the position of the scroll
     */
    getPageScroll: function(){
        var num_scrollX = 0, num_scrollY = 0;
        if (typeof(window.pageYOffset) == 'number') {
            num_scrollY = window.pageYOffset;
            num_scrollX = window.pageXOffset;
        }
        else 
            if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
                num_scrollY = document.body.scrollTop;
                num_scrollX = document.body.scrollLeft;
            }
            else 
                if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
                    num_scrollY = document.documentElement.scrollTop;
                    num_scrollX = document.documentElement.scrollLeft;
                }
        return {
            'x': num_scrollX,
            'y': num_scrollY
        };
    },
    /*
     Gets the size of the Page
     */
    getWindowSize: function(){
        var xScroll, yScroll, windowWidth, windowHeight;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth + window.scrollMaxX;
            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;
            }
        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;
                }
        if (yScroll < windowHeight) {
            pageHeight = windowHeight;
        }
        else {
            pageHeight = yScroll;
        }
        if (xScroll < windowWidth) {
            pageWidth = windowWidth;
        }
        else {
            pageWidth = xScroll;
        }
        return {
            'pageWidth': pageWidth,
            'pageHeight': pageHeight,
            'windowWidth': windowWidth,
            'windowHeight': windowHeight
        };
    },
    /*
     * Preloads Imanages on Page
     */
    preloadImages: function(){
        var d = document;
        if (d.images) {
            if (!d.MM_p) 
                d.MM_p = new Array();
            var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
            for (i = 0; i < a.length; i++) {
                if (a[i].indexOf("#") != 0) {
                    d.MM_p[j] = new Image;
                    d.MM_p[j++].src = a[i];
                }
            }
        }
    },
    /*
     * Find Offset To Body
     */
    findOffsetBody: function(obj){
        var curleft = 0;
        var curTop = 0;
        if (obj.offsetParent) {
            while (1) {
                curleft += obj.offsetLeft;
                if (!obj.offsetParent) 
                    break;
                obj = obj.offsetParent;
            }
        }
        else 
            if (obj.x) {
                curleft += obj.x;
                curTop += obj.y;
            }
        return {
            top: curTop,
            left: curleft
        };
    }    
    
};