var POSITIONING = {
    browserClass : new Object(),

    init : function () {
        //alert( "In init" );
        this.browserClass.isCSS = ( ( document.body && document.body.style ) ? true : false );
        this.browserClass.isW3C = ( ( this.browserClass.isCSS && document.getElementById ) ? true : false );
        this.browserClass.isIE4 = ( ( this.browserClass.isCSS && document.all ) ? true : false );
        this.browserClass.isNN4 = ( ( document.layers ) ? true : false );
        this.browserClass.isIECSSCompat = ( ( document.compatMode && document.compatMode.indexOf( "Css1" ) >= 0 ) ? true : false );
    },

    getInsideWindowWidth : function () {
        if ( window.innerWidth ) {
            return window.innerWidth;
        } else if ( this.browserClass.isIECSSCompat ) {
            return document.body.parentElement.clientWidth;
        } else if ( document.body && document.body.clientWidth ) {
            return document.body.clientWidth;
        }
        return null;
    },

    getInsideWindowHeight : function () {
        if ( window.innerHeight ) {
            return window.innerHeight;
        } else {
            if ( document.body.clientHeight != document.body.parentNode.clientHeight ) {
                return document.body.parentNode.clientHeight;
            } else {
                return document.body.clientHeight;
            }
        }
    },

    moveTo : function ( elemRef, x, y ) {
        var elem = elemRef;
        if ( elem.style ) {
            if ( this.browserClass.isCSS ) {
                var units = ( typeof elem.style.left == "string" ) ? "px" : 0;
                //alert( "Moved to " + x + ", " + y );
                elem.style.left = x + units;
                elem.style.top = y + units;
            } else if ( this.browserClass.isNN4 ) {
                elem.moveTo( x, y );
            }
        }
    },


    centerOnWindow : function ( elemID ) {
        var jqElemID = "#" + elemID;
        elemID = document.getElementById( elemID );
        //alert( "Style " + elemID.style );
        //alert( elemID );
        var scrollX = 0, scrollY = 0;
        if ( document.body && typeof document.body.scrollTop != "undefined" ) {
            scrollX += document.body.scrollLeft;
            scrollY += document.body.scrollTop;
            //alert( "Scrolls " + scrollX + " " + scrollY );
            if ( document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined" &&
                 ( document.body.scrollTop != document.body.parentNode.scrollTop ) ) {
                scrollX += document.body.parentNode.scrollLeft;
                scrollY += document.body.parentNode.scrollTop;
            }
        } else if ( typeof window.pageXOffset != "undefined" ) {
            scrollX += window.pageXOffset;
            scrollY += window.pageYOffset;
        }
        var x = Math.round( ( this.getInsideWindowWidth() / 2 ) -
                              ( $(jqElemID).width() / 2 ) ) + scrollX;
        var y = Math.round( ( this.getInsideWindowHeight() / 2 ) -
                              ( $(jqElemID).height() / 2 ) ) + scrollY;
        x = Math.max( 0, x );
        y = Math.max( 0, y );
        this.moveTo( elemID, x, 0 );
        elemID.style.visibility = "visible";
    }
}
$(document).ready( function () { POSITIONING.init(); });

