/**
 * eCommunities ECMS Geometry Class 
 * 
 * This module defines functions for querying window and document geometry.
 * 
 * windowX/Y(): return the position of the window on the screen
 * viewportWidth/Height(): return the size of the browser viewport area
 * documentWidth/Height(): return the size of the document.
 * horizontalScroll(): return the position of the horizontal scrollbar
 * verticalScroll(): return the position of the vertical scrollbar
 *
 * Note that there is no portable way to query the overall size of the 
 * browser window, so there are no getWindowWidth/Height() functions.
 * 
 * IMPORTANT: This module must be instantiated from the onload after the document has been loaded fully.
 * 
 * @author Unknown. Updated by Kevin Farley
 * @version 2.0
 */

// Declare the required ECMS namespaces if they do not already exist
if (ECMS == null || typeof(ECMS) != "object") { var ECMS = new Object(); }
if (ECMS.ECORE == null || typeof(ECMS.ECORE) != "object") { ECMS.ECORE = new Object(); }
if (ECMS.ECORE.geometry == null || typeof(ECMS.ECORE.geometry) != "object") { ECMS.ECORE.geometry = new Object(); }

ECMS.ECORE.geometry = {

	init: function () {
		this.setDimensions();
	},

	windowX: null,
	windowY: null,
	viewportWidth: null,
	viewportHeight: null,
	horizontalScroll: null,
	verticalScroll: null,
	documentWidth: null,
	documentHeight: null,
	
	elementX: null,
	elementY: null,
	elementWidth: null,
	elementHeight: null,
	
	setDimensions: function () {
		if (window.screenLeft) { // IE and others
			this.windowX = window.screenLeft;
			this.windowY = window.screenTop;
		}
		else if (window.screenX) { // Firefox and others
			this.windowX = window.screenX;
			this.windowY = window.screenY;
		}
		
		if (window.innerWidth) { // All browsers but IE
			this.viewportWidth = window.innerWidth;
			this.viewportHeight = window.innerHeight;
			this.horizontalScroll = window.pageXOffset;
			this.verticalScroll = window.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
			// These functions are for IE6 when there is a DOCTYPE
			this.viewportWidth = document.documentElement.clientWidth;
			this.viewportHeight = document.documentElement.clientHeight;
			this.horizontalScroll = document.documentElement.scrollLeft;
			this.verticalScroll = document.documentElement.scrollTop;
		}
		else if (document.body.clientWidth) {
			// These are for IE4, IE5, and IE6 without a DOCTYPE
			this.viewportWidth = document.body.clientWidth;
			this.viewportHeight = document.body.clientHeight;
			this.horizontalScroll = document.body.scrollLeft;
			this.verticalScroll = document.body.scrollTop;
		}
		
		// These functions return the size of the document.  They are not window 
		// related, but they are useful to have here anyway.
		if (document.documentElement && document.documentElement.scrollWidth) {
			this.documentWidth = document.documentElement.scrollWidth;
			this.documentHeight = document.documentElement.scrollHeight;
		}
		else if (document.body.scrollWidth) {
			this.documentWidth = document.body.scrollWidth;
			this.documentHeight = document.body.scrollHeight;
		}
	},
	
	setElementDimensions: function(elementID) {
		e = document.getElementById(elementID);
		
		this.elementX = e.style.left;
		this.elementY = e.style.top;
		this.elementWidth = e.offsetWidth;
		this.elementHeight = e.offsetHeight;
	}
}
