/*
 * Based on the Yahoo UI library.
 */

/**
 * The IRIS object is the single global object used by the iris-js library.
 * @module iris
 * @title iris-js global
 */
if( typeof IRIS == "undefined" ) {
    /**
     * The IRIS global namespace object.
     * @class IRIS
     * @static
     */
    var IRIS = {};
}

/**
 * Returns the namespace specified and creates it if it doesn't exist
 * <pre>
 * IRIS.namespace("property.package");
 * IRIS.namespace("IRIS.property.package");
 * </pre>
 * Either of the above would create IRIS.property, then
 * IRIS.property.package
 *
 * Be careful when naming packages. Reserved words may work in some browsers
 * and not others. For instance, the following will fail in Safari:
 * <pre>
 * IRIS.namespace("really.long.nested.namespace");
 * </pre>
 * This fails because "long" is a future reserved word in ECMAScript
 *
 * @method namespace
 * @static
 * @param  {String*} arguments 1-n namespaces to create 
 * @return {Object}  A reference to the last namespace object created
 */
IRIS.namespace = function() {
    var a=arguments, o=null, i, j, d;
	for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=IRIS;
        // IRIS is implied, so it is ignored if it is included
        for (j=(d[0] == "IRIS") ? 1 : 0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }
    return o;
};

IRIS.namespace('widget');
IRIS.namespace('util');
IRIS.namespace('clients');

IRIS.getBody = function( win ) {
	var doc;
	if( win ) {
		doc = win.contentDocument;
	}
	else {
		doc = document;
	}
	return doc.getElementsByTagName('body')[0];
}

/*
 * Example module:
IRIS.namespace("myProject");
IRIS.myProject.myModule = function() {
	var privateVar = "foo";
	var privateFunc = function() {};
	return {
		publicVar: "foo",
		publicFunc: function() {}
	}
}();
IRIS.myProject.myModule.publicFunc();
 */

if( typeof console == "undefined" ) {
	var console = {};
	with( console ) {
		log = debug = info = warn = error = time = timeEnd = profile = profileEnd = trace = group = groupEnd = dir = dirxml = function() {};
	}
}

Array.indexOf || (Array.prototype.indexOf = function(v){
   for(var i = this.length; i-- && this[i] !== v;);
	   return i;
});
