/**
 * @namespace
 * Object encapsulates all the custom objects, functions, and variables used on gridmob.com.
 */
var gm = {};


/**
 * @namespace
 * Holds the utility functions
 */
gm.util = {};

/**
 * @namespace
 * Holds the constants
 */
gm.constants = {};

/**
 * @namespace
 * Holds the widgets
 */
gm.widget = {};

/**
 * This function should be the only function written at the global namespace level.  It is a generic 
 * replacement for the getElementById() function.
 * 
 * @param  {String|Array|HTMLElement} el   the identifier(s) that we will use to retrieve HTMLElement(s).
 * @return {HTMLElement|Array}             A DOM reference to an HTML element or an array of HTMLElements.
 */
function $(el) {
	// string
    if (gm.util.isString(el)) { 
        return document.getElementById(el);
    }

	// array
    if (gm.util.isArray(el)) {
        var a=[],i=0;
        for (; i < el.length; i++) {
            a[a.length] = $(el[i]);
        }
        return a;
    }

	// some object ... just pass it back
    return el; 
}

var _ua = navigator.userAgent.toLowerCase();
var _av = navigator.appVersion.toLowerCase();
/**
 * indicates if the operating system is a mac
 * @type Boolean  
 */
var isMac = (_ua.indexOf("macintosh") >= 0) ? true : false;

/**
 * indicates if the operating system is windows
 * @type Boolean  
 */
var isWindows = (_ua.indexOf("windows") >= 0 || _ua.indexOf("win32") >= 0) ? true : false;

/**
 * indicates if the browser is Internet Explorer and what version it is
 * @type int
 */
var isIE = (document.all && _ua.indexOf("opera") < 0) ? parseFloat(_av.split("msie ")[1].split(";")[0]) : 0;

/**
 * indicates if the browser is konqueror
 * @type int
 */
var isKhtml = (_av.indexOf("Konqueror") >= 0 || _av.indexOf("Safari") >= 0) ? parseFloat(_av) : 0;

/**
 * indicates if the browser is mozilla
 * @type int
 */
var isMoz = (_ua.indexOf("Gecko") >= 0 && !isKhtml) ? parseFloat(_av) : 0;

/**
 * indicates if the browser is firefox
 * @type int
 */
var isFF = (_ua.indexOf("firefox") >= 0) ? parseFloat(_ua.split("firefox/")[1].split(" ")[0]) : 0;

/**
 * indicates if the browser is Safari and what version it is
 * @type int
 */	
var isSafari = (_av.indexOf("safari") >= 0) ? parseFloat(_av.split("version/")[1]) || 2 : 0;

/**
 * indicates if the browser is Safari and what version it is
 * @type int
 */	
var isOpera = (_ua.indexOf("opera") >= 0) ? parseFloat(_av) : 0;


(function() { 
	// set global debug variable
	var loc = location.search.substring(1, location.search.length);
	var params = loc.split("&");
	var arr = [];
	
	for (i=0; i<params.length;i++) {
		arr[params[i].substring(0,params[i].indexOf('='))] = params[i].substring(params[i].indexOf('=')+1);
	}
	
	// set the debug values
	gm.isDebug = (arr["gmlocal"] || arr["gmdebug"]) ? true : false;

})();

