/**
 * @fileoverview	The UHG global namespace object.  If UHG is 
 * already defined, the existing UHG object will not be overwritten 
 * so that defined namespaces are preserved.
 * @static
 */
if (typeof UHG == "undefined") {
	var UHG = {};
}

(function () {
	
	/**
	 * Returns the namespace specified and creates it if it doesn't exist
	 * <pre>
	 * UHG.namespace("property.package");
	 * UHG.namespace("UHG.property.package");
	 * </pre>
	 * Either of the above create UHG.property, then UHG.property.package
	 * <p>
	 * Be careful when naming packages. Reserved words may work in some browsers
	 * and not others. For instance, the following will fail in Safari:
	 * <pre>
	 * UHG.namespace("really.long.nested.namespace");
	 * </pre>
	 * This fails because "long" is a future reserved word in ECMAScript				
	 * @static																			
	 * @param	{String}	arguments 1-n namespaces to create, optional
	 * @return	{Object}	reference to the last namespace object created
	 */
	UHG.namespace = function () {
		
		var a=arguments;
		var aLength;
		var d;
		var dLength;
		var i;
		var initialJ;
		var o=null;
		
		// loop cache
		aLength = a.length;
		for (var i = 0; i < aLength; i++) {
			d=a[i].split(".");
			o=UHG;
			dLength = d.length;
			
			// UHG is implied, so it is ignored if it is included
			if (d[0] == "UHG") {
				initialJ = 1;
			} else {
				initialJ = 0;
			}
			for (var j = initialJ; j < dLength; j++) {
				o[d[j]] = o[d[j]] || {};
				o = o[d[j]];
			}
		}
		return o;
	}; 
	
	UHG.log = function log(str) { try { console.log(str); } catch(e) {} }
	
	UHG.namespace('util');
	
	
	/** 
	 * Get URL Parameter (gup) Parse the window.location.href 
	 * value and return the value for the parameter you specify.
	 * @param  {String}    name of parameter
	 * @return {String}    value of requested parameter
	 */
	UHG.util.gup = function( name ) {
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec( window.location.href );
        if( results == null ) {
            return false;
        } else {
            return results[1];
        }
    }
	
	/**
	 * Generates a random number between 0 and 10,000,000,000,000,000
	 * @return	{Number}	returns random number in range
	 */
	UHG.util.randomNum = function () {
		return Math.random()*10000000000000000;
	};
	
	UHG.util.isUndefined = function(val) {
		
		if(!(val) 
			|| val == "undefined" 
			|| val == false
			|| val == "false"
			|| val == ''
			|| val == null
			|| val == "null") {
			
			return true;
		
		} else {
		
			return false;
		
		}
		
	};

	
})();
	
