 /*
 * UI is a user interface library designed ontop of Prototype and Scriptaculous
 * hello
 * 
 * This library is property of DeenSoft 2008. 
 * Inspired by other libs such as ExtJS, YUI and JXLib.
 * testing finally
 * 
 */


/* firebug console supressor for IE/Safari/Opera */

if (!("console" in window) || !("firebug" in console)) {
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
	"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

	window.console = {};
	for (var i = 0; i < names.length; ++i) {
		window.console[names[i]] = function() {};
	}
}


/**
 * Namespace: UI
 * 
 * Main UI object used to extend as a base namespace. We use a similar (well really exactly) same idea
 * as Scriptaculous to include the core and widgets. A better system is needed.
 */
var UI = {
	imagepath: '../images/',
	/*
	 * Version # for UI Lib
	 */
	Version: '0.1',
	/*
	 * basic lib files that are required for the Framework
	 */
	libs: [ "UIListener",
			"UIContentPane", 
			"UILayout", 
			"UISplitter", 
			"UIShim",
			"UIShadow",
			"UIButton", 
			"UIContainer", 
			"UIWindow", 
			"UIMenu", 
			"UITab",
			"UITreeNode", 
			"UITree",
			"UIGrid"],
	/*
	 * Extternal Widgets
	 */
	widgets: [
			"widgets/UIContextMenu",
			"widgets/UICheckBoxTree",
			"widgets/UIAjaxTree",
			"widgets/UIButtonMenu",
			"widgets/UIToolbar",
			"widgets/UIPanel",
			"widgets/UIAccordion"],
	/*
	 * Function: require
	 * Description: Given a path to JS file this will add it to the header tag.
	 */
	require: function(libraryName) {
		document.write('<script type="text/javascript" src="'+libraryName+'"><\/script>');
	},
	/*
	 * Function: load
	 * Description: loads all the widgets and libs.
	 * Params: none
	 */
	load: function() {
		$A(document.getElementsByTagName("script")).findAll( function(s) {
			return (s.src && s.src.match(/prototype\.js(\?.*)?$/))
		}).each( 
			function(s) {
				var path = s.src.replace(/lib\/prototype\.js(\?.*)?$/,'');
				UI.libs.each(
					function(include) { UI.require(path+include+'.js') }
				);
				UI.widgets.each(
					function(include) { UI.require(path+include+'.js') }
				);
			}
		);

	} //end of load function
};
//lets load the libs and widgets.
UI.load();

/**
 * Function: namespace
 * 
 * Used to create a new namespace for UI framework
 * 
 * Usage:
 * 
 * (start code)
 * UI.namespace("UI.my.custom.namespace");
 * (end)
 */
UI.namespace = function()
{
	var a=arguments, o=null, i, j, d;
	for (i=0; i<a.length; i=i+1) {
		d=a[i].split(".");
		o=UI;
		for (j=(d[0] == "UI") ? 1 : 0; j<d.length; j=j+1) {
			o[d[j]]={};
			o=o[d[j]];
		}
	}
	return o;
};
