/*
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Environment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
	/**
	 *	Environment 
	 *	This class provides information about the environment of the executing script
	 *
	 *	@constructor
	 */
	function Environment() {
		// This is static mainly, no need to instantiate
	}
	
	
	/**
	 *	Handle the event where the cursor changes position on the document
	 *
	 *	@private
	 *
	 *	@param e The event that triggered this
	 *
	 *	@return true
	 */
	Environment.handleMouseMove = function(e) {
		if (typeof Environment != 'undefined') {
			if (document.all) {	
				Environment.curX = e.clientX + document.body.scrollLeft;
				Environment.curY = e.clientY + document.body.scrollTop;
			}
			else {
				Environment.curX = e.pageX;
				Environment.curY = e.pageY;
			}
		}
		return true;
	}
	
	/**
	 *	Get the X position of the cursor
	 *
	 *	@return the X position of the cursor
	 */
	Environment.getCursorX = function() {
		return Environment.curX;
	}
	
	/**
	 *	Get the Y position of the cursor
	 *
	 *	@return the Y position of the cursor
	 */
	Environment.getCursorY = function() {
		return Environment.curY;
	}

	/**
	 *	Get the scroll bar size
	 *
	 *	@return the size of the scroll bars
	 */
	Environment.scrollBarWidth = function() {
		if (Environment.i_scroll_width == undefined) {
			var sco = document.createElement('DIV');
			sco.style.visibility = "hidden";
			sco.style.position = "absolute";
			sco.style.width = "40px";
			sco.style.height = "60px";
			sco.style.overflow = "scroll";
			
				var sci = document.createElement('DIV');
				sci.style.height = "80px";
				sci.innerHTML = "&nbsp;";
				sco.appendChild(sci);
				
			document.body.appendChild(sco);
			
			Environment.i_scroll_width = parseInt(sco.offsetWidth) - parseInt(sci.offsetWidth);
			
			document.body.removeChild(sco);
		}
		return Environment.i_scroll_width;
	}
	
	
	/**
	 *	Get the width of the browsers viewport
	 *
	 *	@return the width of the browsers viewport
	 */
	Environment.browserWidth = function() {
		return (document.all ? document.body.offsetWidth : window.innerWidth);
	}
	
	/**
	 *	Get the height of the browsers viewport
	 *
	 *	@return the height of the browsers viewport
	 */
	Environment.browserHeight = function() {
		// 
		return (document.all ? document.documentElement.offsetHeight : window.innerHeight);
	}
	
	/**
	 *	Get the name of the users browser
	 *
	 *	@return the name of the users browser
	 */
	Environment.browserName = function() {
		return Environment.i_browserName;
	}
	
	/**
	 *	Get the version of the users browser
	 *
	 *	@return the version of the users browser
	 */
	Environment.browserVersion = function() {
		return Environment.i_browserVersion;
	}
	
	/**
	 *	Get the major version number of this browser
	 *
	 *	@return the major version number of the browser
	 */
	Environment.browserMajorVersion = function() {
		return Environment.i_browserMajor;
	}
	
	/**
	 *	Check to see if this is an IE browser
	 *
	 *	@return true if this is MSIE or Opera, false otherwise
	 */
	Environment.isIE = function() {
		return Environment.i_isIE;
	}

	/**
	 *	Get the dimensions of a text segment under the influence of a given class
	 *
	 *	@param text The text to check the dimensions of
	 *	@param cssClass The class name to apply 
	 *	@param width (Optional) The maximum width the text can use
	 *
	 *	@return an array with two elements.  The first is the width, the second is the height
	 */
	Environment.getTextDimension = function(text, cssClass, width) {
		if (Environment.i_textDimCache == undefined) {
			Environment.i_textDimCache = Array();
		}
		var ret;
		if (Environment.i_textDimCache[text + ":" + cssClass + ":" + (width != undefined ? width : "x")] != undefined) {
			ret = Environment.i_textDimCache[text + ":" + cssClass + ":" + (width != undefined ? width : "x")];
		}
		else {
			var ret = Array();
			var ck = document.createElement('DIV');
			ck.className = cssClass;
			ck.style.position = "absolute";
			ck.innerHTML = text;
			document.body.appendChild(ck);
			if (parseInt(ck.offsetWidth) > width && width != undefined) {
				ck.style.width = width + "px";
			}
			ret[0] = parseInt(ck.offsetWidth);
			ret[1] = parseInt(ck.offsetHeight);
			document.body.removeChild(ck);
			Environment.i_textDimCache[text + ":" + cssClass + ":" + (width != undefined ? width : "x")] = ret;
		}
		return ret;
	}
	 

	/**
	 *	Initialize the environment
	 *
	 *	@return true
	 */
	Environment.init = function() {
		
		var x_appVersion = navigator.appVersion;
		var x_userAgent = navigator.userAgent;

		Environment.i_isIE = false;

		if ((vpos = x_userAgent.indexOf('MSIE')) >= 0) {
			Environment.i_browserName = "Microsoft Internet Explorer";
			Environment.i_browserVersion = parseFloat(x_userAgent.substring(vpos + 5));
			Environment.i_browserMajor = Math.floor(Environment.i_browserVersion);
			Environment.i_isIE = true;
		}
		else if ((vpos = x_userAgent.indexOf('Opera')) >= 0) {
			Environment.i_browserName = "Opera";
			Environment.i_browserVersion = parseFloat(x_userAgent.substring(vpos + 6));
			Environment.i_browserMajor = Math.floor(Environment.i_browserVersion);
		}
		else if ((npos = x_userAgent.lastIndexOf(' ') + 1) < (vpos=x_userAgent.lastIndexOf('/'))) {
			Environment.i_browserName = x_userAgent.substr(npos, vpos);
			Environment.i_browserVersion = parseFloat(x_userAgent.substring(vpos + 1));
			if (!isNaN(Environment.i_browserVersion)) {
				Environment.i_browserMajor = Math.floor(Environment.i_browserVersion);
			}
			else {
				Environment.i_browserMajor = Environment.i_browserVersion = 0;
			}	
		}
		
		if (Environment.i_browserName == "") {
			Environment.i_browserName = navigator.appName;
			
		}
		EventControl.listen(document.body, "onmousemove", Environment.handleMouseMove, this);

	}
	

