/* Copyright (c) 2007 Pimentech Inc. All rights reserved. */


/*
 * Debug messages
 */

var js_debug = false;

if (YAHOO && YAHOO.widget.Logger) {
	if (js_debug) {
		activate_logs();	
	}
}

function activate_logs() {
	YAHOO.widget.Logger.enableBrowserConsole();
	YAHOO.log("Unable these messages in PIMENTECH.js with 'js_debug = false'.");	
}

function debug_msg(message) {
	if (js_debug) {
		if (YAHOO) {
			YAHOO.log(message);
		}
		else if (typeof console == 'object') {
			// Debug sur console firebug
			console.log(message);
		}
		else if (js_debug && 
				 !confirm('Javascript debug message\n' + 
						  '-------------------------------------------------\n' + message + '\n' +
						  '-------------------------------------------------\n' + 'Keep debugging mode on ?')
				 ) {
			js_debug = false;
		}
	}
}


/**
 * @class The Pimentech global namespace
 */
var PIMENTECH = function() {

    return {

        /**
         * Pimentech presentation platform utils namespace
         */
        util: {},
		widget: {},

        /**
         * Returns the namespace specified and creates it if it doesn't exist
         *
         * PIMENTECH.namespace("property.package");
         * PIMENTECH.namespace("PIMENTECH.property.package");
         *
         * Either of the above would create PIMENTECH.property, then
         * PIMENTECH.property.package
         *
         * @param  {String} sNameSpace String representation of the desired 
         *                             namespace
         * @return {Object}            A reference to the namespace object
         */
        namespace: function( sNameSpace ) {

            if (!sNameSpace || !sNameSpace.length) {
                return null;
            }

            var levels = sNameSpace.split(".");

            var currentNS = PIMENTECH;

            // PIMENTECH is implied, so it is ignored if it is included
            for (var i=(levels[0] == "PIMENTECH") ? 1 : 0; i<levels.length; ++i) {
                currentNS[levels[i]] = currentNS[levels[i]] || {};
                currentNS = currentNS[levels[i]];
            }

            return currentNS;

        }
    };

} ();
