//
// screen
//


var SCREEN={
	// Get a reference to the document body
	body:null,
	documentHeight:0,
	documentWidth:0,
	scrollLeft:0,
	scrollTop:0,
	viewportHeight:0,
	viewportWidth:0,
	getBody:function(){
		if (document.body){
			return document.body;
    		}
		var bodies=$.getByTag("body",document);
      	if (bodies!=null && bodies.length>0){
        	return bodies[0];
      		}
    	return null;
  		},
  
	// Get the height of the entire document
	getDocumentHeight:function() {
    	var body = SCREEN.getBody();
    	var innerHeight = (GLOBALS.isDefined(self.innerHeight)&&!isNaN(self.innerHeight))?self.innerHeight:0;
    	if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
        	var topMargin = parseInt($.getStyle(body,'marginTop'),10) || 0;
        	var bottomMargin = parseInt($.getStyle(body,'marginBottom'), 10) || 0;
      		return Math.max(body.offsetHeight + topMargin + bottomMargin, document.documentElement.clientHeight, document.documentElement.scrollHeight, GLOBALS.zero(self.innerHeight));
    		}
    	return Math.max(body.scrollHeight, body.clientHeight, screen.zero(self.innerHeight));
  		},

	// Get the width of the entire document
	getDocumentWidth:function(){
    	var width = 0;
    	var body = SCREEN.getBody();
    	if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
        	var rightMargin = parseInt($.getStyle(body,'marginRight'),10) || 0;
        	var leftMargin = parseInt($.getStyle(body,'marginLeft'), 10) || 0;
			width = Math.max(body.offsetWidth + leftMargin + rightMargin, document.documentElement.clientWidth);
    	} else {
      		width =  Math.max(body.clientWidth, body.scrollWidth);
    		}
    	if (isNaN(width) || width==0) {
      		width = GLOBALS.zero(self.innerWidth);
    		}
    	return width;
		},
  
	// Get the amount that the main document has scrolled from left
	getScrollLeft:function(){
    	if (document.documentElement && GLOBALS.isDefined(document.documentElement.scrollLeft) && document.documentElement.scrollLeft>0) {
      		return document.documentElement.scrollLeft;
    		}
    	if (document.body && GLOBALS.isDefined(document.body.scrollLeft)) {
      		return document.body.scrollLeft;
    		}
    	return null;
  		},

	// Get the amount that the main document has scrolled from top
	getScrollTop:function(){
    	if (document.documentElement && GLOBALS.isDefined(document.documentElement.scrollTop) && document.documentElement.scrollTop>0){
      		return document.documentElement.scrollTop;
    		}
    	if (document.body && GLOBALS.isDefined(document.body.scrollTop)){
      		return document.body.scrollTop;
    		}
    	return null;
  		},
  
	// Get the height of the viewport (viewable area) in the browser window
	getViewportHeight:function(){
    	if (!window.opera && document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
      		return document.documentElement.clientHeight;
    	} else if (document.compatMode && !window.opera && document.body) {
      		return document.body.clientHeight;
    		}
    	return GLOBALS.zero(self.innerHeight);
  		},

	// Get the width of the viewport (viewable area) in the browser window
	getViewportWidth:function(){
    	if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
      		return document.documentElement.clientWidth;
    	} else if (document.compatMode && document.body) {
      		return document.body.clientWidth;
    		}
    	return GLOBALS.zero(self.innerWidth);
  		},
  
	init:function(){
		SCREEN.body=SCREEN.getBody();
		SCREEN.documentHeight=SCREEN.getDocumentHeight();
		SCREEN.documentWidth=SCREEN.getDocumentWidth();
		// this doesn't make sense anymore... since these can change after this object has been created
		SCREEN.scrollLeft=SCREEN.getScrollLeft();
		SCREEN.scrollTop=SCREEN.getScrollTop();
		SCREEN.viewportHeight=SCREEN.getViewportHeight();
		SCREEN.viewportWidth=SCREEN.getViewportWidth();
		}


};


/*
	might be kind of nice to run an init to run all the functions so, say, 
	"viewportHeight" is simply a property of the SCREEN object
*/
// GLOBALS.addOnload(SCREEN.init);

//