/** 
 * @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: {}};

// Shorthand the YUI Selector method - ala jQuery.
var $ = $ || YAHOO.util.Selector.query;

/** 
 * Main configuration values 
 */
UKISA.env = {
	REGION: "EUK",
	CODE: "ICI",
	SITE: "Dulux Trade",
	SITESTAT: "dulux_trade",
	onDOMReady: function() { // Run when the DOM has loaded

		// Add the clear default to the mini search.
		UKISA.util.clearDefault("mini-search-field");

		// Cufon font replacement goes here and makes use of YUI Selector to gather the elements to style.
		if (Cufon && YAHOO.util.Selector) {
			var replace = [
				/*
				"#home-page h1", 
				"#content > h1", 
				"#content h2", 
				"div.content h3",
				".section h1",
				".page-section-1 > h1",
				".page-section-2 > h1",
				"#content .section h3",
				"ul.brochures h3",
				".datasheet-section h3",
				"#products-landing-page ul.strong-products h3",
				"#aside div.section h3",
				"div.page-section-3 div.section h3",
				"div.accordian-nav > h3",
				"div.yui-content h2"
				*/
				"h1, h2, h3",
				"div.mood-section-nav a",
				"#ecosure-landing-page blockquote"
			];

			Cufon.replace(YAHOO.util.Selector.query(replace.join(", ")));
		}
	},
	onLoad: function() { // Run when the content has loaded
		var i, el;

		// Load the stripe card tooltips if there are any.
		UKISA.site.Navigation.stripecardTooltips();

		// Find all the print buttons.
		el = $("a.print", "content");
		i = el.length;
		for (; i--;) { el[i].onclick = function() { UKISA.util.print(); return false; }; }

		// This adds a modal box for links e.g. terms & conditions.
		el = $("a.modal", "content");
		i = el.length;
		for (; i--;) { el[i].onclick = function() { UKISA.site.Navigation.terms(this); return false; }; }
	}
};

/**
 * Create the localisation namespace
 */
UKISA.locale[UKISA.env.SITE] = {
	// L10n values here (strings, functions, etc.)
	widget: {
		FormValidation: {
			display: {
				xOffset: -15,
				yOffset: 0
			}
		},
		Flash: {
			supports: "8.0.0", // Default supported version.	
			width: 512,	// Default width.
			height: 288, // Default width.
			flashDir: "/web/flash/",
			movieDir: "/web/movies/",
			swfobjectDir: "/web/scripts/swfobject.js",
			params: { // Default params.
				"quality": "high",
				"scale": "noscale",
				"pluginspage": "http://www.macromedia.com/go/getflashplayer",
				"wmode": "transparent"
			},
			vars: { // Default variables.
				"MM_ComponentVersion": "1",
				"skinName": "/web/flash/Halo_Skin_3",
				"autoPlay": "true",
				"autoRewind": "true"
			},
			skins: {
				"Halo_Skin_3": {
					top: 11,
					right: 11,
					bottom: 40,
					left: 11
				}
			},
			attributes: {},
			callback: null
		}
	},
	site: {
		Order: {
			Basket: {
				automaticAddToBasket: true
			}
		}
	}
};

/**
 * 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.onLoad);

	// Create the site namespace
	UKISA[UKISA.env.SITE] = {};

})();