/**
 * @name        Global Initialisation
 * @overview    An automated documentation publishing system for JavaScript.
 * @version        0.1
 * @revision    2007-06-01 00:00:00
 * @author        Michael Ord <a href="mailto:michael.ord@think.eu">michael.ord@think.eu</a>
 */
core={}
 
if (typeof ThinkCo == "undefined") {
    /**
     * The ThinkCo global namespace object.  If ThinkCo is already defined, the
     * existing ThinkCo object will not be overwritten so that defined
     * namespaces are preserved.
     * @class ThinkCo
     * @static
     */
    var ThinkCo = {};
};
/**
 * Returns the namespace specified and creates it if it doesn't exist
 * <pre>
 * ThinkCo.namespace("property.package");
 * ThinkCo.namespace("ThinkCo.property.package");
 * </pre>
 * Either of the above would create ThinkCo.property, then
 * ThinkCo.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>
 * ThinkCo.namespace("really.long.nested.namespace");
 * </pre>
 * This fails because "long" is a future reserved word in ECMAScript
 *
 * @function namespace
 * @static
 * @param  {String*} arguments 1-n namespaces to create
 * @return {Object}  A reference to the last namespace object created
 */
ThinkCo.namespace = function (ns) {
    if (!ns || !ns.length) {
        return null;
    };
    var levels    = ns.split (".");
    var nsobj    = ThinkCo;
    for (var i = (levels [ 0 ] == "ThinkCo") ? 1 : 0; i < levels.length; ++i) {
        nsobj [ levels [ i ] ] = nsobj [ levels [ i ] ] || {};
        nsobj = nsobj [ levels [ i ] ];
    };
    return nsobj;
};
ThinkCo.namespace ('Enhance');
/**
 * @function    Enhance
 * @description    DESCRIPTION HERE
 * @param        {Object} styleName
 */
ThinkCo.Enhance = function (styleName) {
    // get all the link elements in the page
    var tmp_link    = document.getElementsByTagName ('link');
    // loop through all the elements
    for (var i = 0; i < tmp_link.length; i++) {
        // quick reference to the element
        var tmp_ref    = tmp_link [ i ];
        // check for attribute
        if (tmp_ref.getAttribute ('rel')) {
            // if the element is a stylesheet
            if (tmp_ref.getAttribute ('rel').toLowerCase () == 'stylesheet') {
                // get the source
                var tmp_src        = tmp_ref.getAttribute ('href');
                // regular expression to strip down the filename
                var tmp_regEx    = /\/([a-zA-Z0-9]+).css/;
                // split the filename based on the regular expression
                var tmp_matches    = tmp_src.match (tmp_regEx);
                // if there are matches
                if (tmp_matches) {
                    // create and build a new stylesheet that is used to import the enhanced styles
                    var tmp_href    = tmp_ref.getAttribute ('href').replace (tmp_matches [ 1 ], styleName);
                    var tmp_el        = YAHOO.util.Dom.create ('link', { rel : 'stylesheet', href : tmp_href, type : 'text/css' });
                    var tmp_head    = document.getElementsByTagName ('head') [ 0 ];
                    tmp_head.appendChild (tmp_el);
                    break;
                };
            };
        };
    };
};
/*
 * add enhance class to the body (which should have the id of 'iRoot')
 */
YAHOO.util.Event.onDOMReady ( function () {
    if (YAHOO.util.Dom.get ('iRoot')) {
        YAHOO.util.Dom.addClass    ('iRoot', 'enhance');
    };
});




YAHOO.util.Dom.create = function(tagName) {
	/**
	 * @class _util Private util object
	 */
	_util = {
		/**
		 * Converts a text string into a DOM object
		 * @param {String} txt String to convert
		 * @returns A string to a textNode
		 */
		_makeTxtObject: function(txt)
		{
			return document.createTextNode(txt);
		},
		/**
		 * Takes an Array of DOM objects and appends them as a child to the main Element
		 * @param {Array} txt String to convert
		 * @param {HTMLElement} elm A reference to the main Element that the children will be appended to
		 */
		_makeChildren: function(arr, elm)
		{
			for (var i in arr) {
				_val = arr[i];
				if (typeof _val == 'string') {
					_val = this._makeTxtObject(_val);
				};

				if ( typeof ( _val ) == 'function' ) {
					continue;
				}

				elm.appendChild(_val);
			};
		},
		_makeStyleObject: function(attrsObj, elm)
		{
			for (var i in attrsObj) {
				switch (i.toLowerCase())
				{
					case 'listener':
						if (attrsObj[i] instanceof Array) {
							var ev = attrsObj[i][0];
							var func = attrsObj[i][1];
							var base = attrsObj[i][2];
							var scope = attrsObj[i][3];
							YAHOO.util.Event.addListener(elm, ev, func, base, scope);
						};
						break;
					case 'classname':
					case 'class':
						elm.className = attrsObj[i];
						break;
					case 'style':
						var _tmp = attrsObj[i].replace(' ', '');
						_tmp = _tmp.split(';');
						for (x in _tmp)
						{
							if (x) {
								var __tmp = _tmp[x].replace(' ', '');
								__tmp = _tmp[x].split(':');
								if (__tmp[0] && __tmp[1]) {
									var _attr = __tmp[0].replace(' ', '');
									var _val = _util._trim(__tmp[1]);
									if (_attr && _val) {
										if (_attr.indexOf('-') != -1) {
											_attr = _util._fixStyle(_attr);
										};
										eval('elm.style.' + _attr + ' = "' + _val + '";');
									};
								};
							};
						};
						break;
					default:
						elm.setAttribute(i, attrsObj[i]);
						break;
				}
			}
		},
		_fixStyle: function(str) {
			var _tmp = str.split('-');
			var _new_style = _tmp[0];
			for (var i = 1; i < _tmp.length; i++) {
				_new_style += _tmp[i].substring(0, 1).toUpperCase() + _tmp[i].substring(1, _tmp[i].length);
			};
			return _new_style;
		},
		_trim: function(str) {
			return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
		}
	};
	tagName = tagName.toLowerCase();
	elm = document.createElement(tagName);
	var txt = false;
	var attrsObj = false;
	if (!elm) { return false; };
	for (var i = 1; i < arguments.length; i++) {
		txt = arguments[i];
		if (typeof txt == 'string') {
			_txt = _util._makeTxtObject(txt);
			elm.appendChild(_txt);
		} else if (txt instanceof Array) {
			_util._makeChildren(txt, elm);
		} else if (typeof txt == 'object') {
			_util._makeStyleObject(txt, elm);
		};
	};
	return elm;
}






