﻿/**
 * @name        Global Initialisation
 * @overview    An automated documentation publishing system for JavaScript.
 * @version        0.1
 * @revision    2007-06-01 00:00:00
 * @author        Michael Ord
 */
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');
    };
});