/** 
 ** File: 		ig.js
 ** 
 ** Created:   02/07/06     By:        Martin (ext 4053)
 ** Edited:    01/04/08     By:        Peter Mouland 
 **
 ** Dependencies: None
 **
 ** Notes:
 ** This script creates the window-level IG object. Other subclasses plug into
 ** this using their various constructors. By default the "util" namespace is
 ** created as a subclass to the object.
 ** 
 ** Version: 	2.0
 **/
 
 
/**
 * IG global namespace
 * @constructor
 */
var IG = window.IG || {};
window.d = document;
window.isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
window.isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
window.isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function gE(e) { 
	return d.getElementById(e); 
}
function gT(e){
   return d.getElementsByTagName(e);
}
function getQS(p) {
	/* Purpose: Get a querystring parameter variable value
	 * Usage: getQS([String]);
	 * Arguments: Parameter variable string
	 * Returns: String
	 */
	return new RegExp("[?&]+"+p+"=([^&$]*)", "gi").test(d.location.href) ? RegExp.$1 : "";
}
function gC(className, tag){
	var arrObj = new Array();
	var tags = gT(tag);
	for (var x=0; x<tags.length; x++){
		if (tags[x].className && tags[x].className.indexOf(className)>=0){
			arrObj.push(tags[x])
		}
	}
	return arrObj;
}


/**
 * Returns the namespace specified and creates it if it doesn't exist
 * IG.namespace("property.package");
 * The above would create IG.property.package
 * @param  {String} s String representation of the desired namespace
 * @return {Object}   A reference to the namespace object
 */
IG.namespace = function(s) {
    if(!s || !s.length) {
        return null;
    }

    var levels = s.split(".");
    var ns = IG;

    for(var i=(levels[0] == "IG") ? 1 : 0; i<levels.length; ++i) {
        ns[levels[i]] = ns[levels[i]] || {};
        ns = ns[levels[i]];
    }
    return ns;
};


//Create an IG.util namespace
IG.namespace("util");

var script, elHead, type;
type   = 'text/javascript';
elHead = document.getElementsByTagName('head')[0];
script = document.createElement('script');
script.type = type;
script.src =  '/lib/js/ig_extender.js?2';
elHead.appendChild(script);  

/**
 ** The IG.util.Loader is an onload stacker enabling
 ** multiple onload routines to be run.
 ** 
 **/
IG.util.Loader = {

	/** onload stacker
	 * @param (Function) fn
	 */
	add: function(fn) {
		if(typeof fn=="undefined") return;
		if(window.addEventListener) {
			window.addEventListener("load", fn, false);
		} else if (typeof window.attachEvent != "undefined") {
			window.attachEvent("onload", fn);
		} else {
			var oldOnload = window.onload;
			if(typeof(window.onload) != "function") {
				window.onload = function() {
						fn();
				};
			} else {
				window.onload = function() {
					oldOnload();
					fn();
				};
			}
		}
	}	
};

