/** 
 * @fileOverview Site configuration and localisation
 * @author Oliver Bishop / Tom McCourt
 * @version 1.12.0
 * @changeLog Added a method to create namespaces.
 */

/* This sets the global namespaces */
var UKISA = {env: {}, locale: {}, widget: {}, util: {}, site: {}};

/** 
 * Main configuration values 
 */
UKISA.env = {
	REGION: "EUK",
	CODE: "ICI",
	SITE: "ICI Paints",
	SITESTAT: "ici_trade",
	onDOMReady: function() { // Run when the DOM has loaded

		// Cufon font replacement goes here and makes use of YUI Selector to gather the elements to style.
		if (Cufon && YAHOO.util.Selector) {
			var replace = [
				"h1.H1Landing",
				".landing-page .page-section-1 h2",
				".landing-page .page-section-2 h2",
				".landing-page .page-section-3 h2",
				".landing-page .page-section-4 h2",
				".landing-page h4",
				".page-section-1 h1.cufon",
				".page-section-1 h2.cufon",
				".page-section-1 h3.cufon",
				".page-section-1 h4.cufon",
				".page-section-2 h1",
				".page-section-2 h2",
				".page-section-2 h3",
				".page-section-2 h4",
				".page-section-3 h2",
				".page-section-3 h3",
				"p.LandingPromoHeading",
				"p.HomeToolsHeading",
				".tdHomeLoginBox h2"
			];

			Cufon.replace(YAHOO.util.Selector.query(replace.join(", ")));
		}
	},
	onContentReady: function() {}
};

/**
 * Create the localisation namespace
 */
UKISA.locale[UKISA.env.SITE] = {};

/**
 * Code required to work with the configuration file. Contains a getter method for l10n, site code initialisation.
 */
(function() {
	/**
	 * This retrieves the localised value as specified by the key.
	 *
	 * @name get
	 * @memberOf UKISA.locale
	 * @param {String} key The variable that holds the localised data.
	 * @returns {?} Returns whatever is held against the key e.g. function, string, integer
	 */
	UKISA.locale.get = function(key) {
		var i, value;

		key = key.split(".");
		value = UKISA.locale[UKISA.env.SITE][key[0]];

		if (value) {
			for (i = 1, ix = key.length; i < ix; i++) {
				value = value[key[i]];
			}
			
		
			if (typeof value[UKISA.env.REGION] !== "undefined") {
				value = value[UKISA.env.REGION];
			}	
		}	

		return (value !== "undefined") ? value : null;
	};

	/**
	 * Create a namespace for the UKISA library.
	 *
	 * @example UKISA.namespace("UKISA.widget");
	 * @example UKISA.namespace("widget");
	 * @example UKISA.namespace("UKISA.widget", "UKISA.site");
	 * @example UKISA.namespace("UKISA.widget.Rollover");
	 */
	UKISA.namespace = function(n) {
		var ukisa, args, i, ix, j, jx, namespaces, name;

		args = arguments;
		ukisa = UKISA;
		
		// Loop through the arguments to add multiple namespaces.
		for (i = 0, ix = args.length; i < ix; i++) {
			namespaces = args[i].split(".");

			name = namespaces[0];
			for (j = (name === "UKISA") ? 1 : 0, jx = namespaces.length; j < jx; j++) {
				name = namespaces[j];
				
				// Check and assign a namespace.
				ukisa[name] = ukisa[name] || {};
			}
		}
	};


	// Assign the global code init as set in the config to YUI
	YAHOO.util.Event.onDOMReady(UKISA.env.onDOMReady);

	// Assign the global code init as set in the config to YUI
	YAHOO.util.Event.addListener(window, "load", UKISA.env.onContentReady);

	// Create the site namespace
	UKISA[UKISA.env.SITE] = {};
})();
