		(function() {
			var Event = YAHOO.util.Event,picker;

			Event.onDOMReady(function() {
	
				// If load colours from URL if 'cc=' is in the address, otherwise try cookies
				if (document.location.href.indexOf('cc=') > -1) {
					loadSettingsFromURL();
				} else {
					loadSettingsFromCookies();
				}
				
				// Initialise Colours
				//applyAllColors();
				//applyBackgrounds();
				
				picker = new YAHOO.widget.ColorPicker("colourPicker", {
				    showcontrols: true,
				    showhexcontrols: true,
				    showhexsummary: true,
				    showhsvcontrols: true,
				    showrgbcontrols: true,
					images: {
						PICKER_THUMB: "/au/yui/colorpicker/assets/picker_thumb.png",
						HUE_THUMB: "/au/yui/colorpicker/assets/hue_thumb.png" 
						}
				});
				
				//a listener for logging RGB color changes;
				//this will only be visible if logger is enabled:
				var onRgbChange = function(o) {
					colorCollection[currentColorSelector] = picker.get("hex");
					applyAllColors();
				}
				
				//subscribe to the rgbChange event;
				picker.on("rgbChange", onRgbChange);
			
				//use setValue to reset the value to white:
				Event.on("reset", "click", function(e) {
					var resetAllowed = setCookie( COLOR_COOKIE, '', 'delete' );
					colorCollection = copyArray(defaultColorCollection);
					applyAllColors();
					closeAndSave();
				});
				
				Event.on("showPicker1", "click", function(e) {

					currentColorSelector = C1;
					picker.set("hex", colorCollection[currentColorSelector]);
					
					// Save if already editing
					if (document.getElementById('colourPicker').style.visibility == 'visible') {
						closeAndSave();
					}

					document.getElementById('colourPicker').style.visibility='visible';
				});
				
				Event.on("showPicker2", "click", function(e) {
					
					currentColorSelector = C2;
					picker.set("hex", colorCollection[currentColorSelector]);
					
					// Save if already editing
					if (document.getElementById('colourPicker').style.visibility == 'visible') {
						closeAndSave();
					}
					
					document.getElementById('colourPicker').style.visibility='visible';

				});
				
				Event.on("showPicker3", "click", function(e) {
					
					currentColorSelector = C3;
					picker.set("hex", colorCollection[currentColorSelector]);
					
					// Save if already editing
					if (document.getElementById('colourPicker').style.visibility == 'visible') {
						closeAndSave();
					}
					
					document.getElementById('colourPicker').style.visibility='visible';

				});
				
				Event.on("showPicker4", "click", function(e) {
					
					currentColorSelector = C4;
					picker.set("hex", colorCollection[currentColorSelector]);
					
					// Save if already editing
					if (document.getElementById('colourPicker').style.visibility == 'visible') {
						closeAndSave();
					}
					
					document.getElementById('colourPicker').style.visibility='visible';

				});

				Event.on("closeAndSave", "click", function(e) {
					closeAndSave();
				});
				
				Event.on("exportColorScheme", "click", function(e) {
					exportColorScheme();
				});
		
			});
		})();
		
		function applyAllColors() {
			var currentElement = null;
			
			for (var i=0; i < NUMBER_OF_BG_COLORS; i++) {
				for (var j=0; j < cssIdsCollection[i].length; j++) {
					currentElement = document.getElementById(cssIdsCollection[i][j]);
					if (currentElement) {
						document.getElementById(cssIdsCollection[i][j]).style.backgroundColor='#' + colorCollection[i];
					} else {
						debug("Could not find element '" + cssIdsCollection[i][j] + "'");
					}
				}
			}
		}
		
		function applyBackgrounds() {
			//var bodyContentFlashProxy = new FlashProxy(bodyContentFlashProxyUID, '/au/flash/common/JavaScriptFlashGateway.swf');
		}
		
		function closeAndSave() {
			writeCookie(COLOR_COOKIE, colorCollection);
			document.getElementById('colourPicker').style.visibility='hidden';
			document.getElementById('exportUrlPanel').style.visibility='hidden';
		}
		
		function loadSettingsFromCookies() {
			// Import colour settings
			var colors = retrieveCookie( COLOR_COOKIE );
			
			//debug("Cookie value is: " + colors);
			
			if (colors) {
				importColours(colors);
			}
		}
		
		function loadSettingsFromURL() {
			
			var currentAddress = document.location.href;
			
			if (currentAddress.indexOf('&cc=') > -1 || currentAddress.indexOf('?cc=') > -1) {
				// extract parameter value
				var regex = new RegExp(".+\\?", "g");
				var urlParameters = currentAddress.replace(regex, '');	// delete all characters but parameters
				var paramArray = null;
				var ccValue = '';
				var ccArray = null;
				
				// If multiple parameters in address
				if (urlParameters.indexOf('&') > -1) {
					paramArray = urlParameters.split("&");
					var ccIndex = 0;
					// find the matching parameter
					for (var i=0; i < paramArray.length; i++) {
						
						if (paramArray[i].indexOf('cc=') > -1) {
							var regex2 = new RegExp("^cc=");
							ccValue = paramArray[i].replace(regex2, '');	// delete 'cc=' from parameter
							break;
						}
					}
				} else { // only 1 parameter
					if (urlParameters.indexOf('cc=') > -1) {
						var regex2 = new RegExp("^cc=");
						ccValue = urlParameters.replace(regex2, '');
					}
				}
				
				// validate value
				if (ccValue == null || ccValue.length < 6) {
					alert ('invalid colour configuration, cc=' + ccValue)
					return;
				}
				
				// import value
				var importSuccessful = importColours(ccValue);
				if (!importSuccessful) {
					alert('The colour setting you have entered is incorrect. \n\nPlease check that it was copied properly and try again.');
					return;
				}
				
				// Prompt to save
				var params = { 
					ok: 'Yes', 
					cancel: 'No', 
					message: 'You are now viewing the new colour scheme. <br>Would you like to save this as your default?',
					ok_cb: do_ok,
					cancel_cb: do_cancel };
				
				custom_confirm(params);
			} 
			
			// do nothing by default
		}
		
		function clearCookies() {
			var deleteAllowed = true;
			
			deleteAllowed = deleteCookie(COLOR_COOKIE);
			if (deleteAllowed = false) 
				return false;
			
			deleteAllowed = deleteCookie(COLOR_COOKIE, COOKIE_PATH);
			if (deleteAllowed = false) 
				return false;
			
			deleteAllowed = deleteCookie(COLOR_COOKIE, COOKIE_PATH, COOKIE_DOMAIN);
			if (deleteAllowed = false) 
				return false;
			
			return true;
		}

		function writeCookie(name, value) {

			var cookieAccepted = false;
			var processedValue = null;
			
			if (isArray(value)) {
				processedValue = value.join(".");
			} else {
				processedValue = value;
			}
			
			var clearAllowed = clearCookies();
			if (!clearAllowed)
				debug('Clear cookies not allowed');
			
			// artist site should be configured to only use one primary domain. All other domains should forward to it. 
			// This is a check that the current address matches the solo domain configured in javascript 
			var isSpecificDomain = (document.location.href.indexOf(COOKIE_DOMAIN + '/') > -1);
			
			if (isSpecificDomain) {	
				cookieAccepted = setCookie( name, processedValue, COOKIE_LIFE, COOKIE_PATH, COOKIE_DOMAIN);
			} else {
				// write cookie against whatever the current domain is
				cookieAccepted = setCookie( name, processedValue, COOKIE_LIFE, COOKIE_PATH);
			}
			
			if (!cookieAccepted) {
				alert ('Please ensure that you have cookies enabled in your browser to save your choice of colours');
			} else {
				// cookie saved message
			}
		}
		
		function exportColorScheme() {
			var serialised = colorCollection.join(".");
			// join address with serialsed parameter and display to user.
			var currentAddress = document.location.href;
			var exportURL = currentAddress;
			
			if (currentAddress.indexOf("?") > -1) {
				exportURL += '&cc=' + serialised;
			} else {
				exportURL += '?cc=' + serialised;
			}
			
			document.getElementById('exportUrlTextArea').value = exportURL;
			document.getElementById('exportUrlPanel').style.visibility='visible';
			document.getElementById('exportUrlTextArea').select();
		}
		
		function importColours(input) {

			var tmpArray = input.split(".");
			
			// Store if array is valid
			if (isArray(tmpArray) && tmpArray.length >= NUMBER_OF_BG_COLORS) {
				colorCollection = tmpArray;
				return true
			} 
			
			debug('importColours(input) - import array not valid. Loading defaults.');
			return false;
			
		}
		
		// Iterate through a list of CSS classes and bulk update this attribute
		function updatecss(classArray,element,value) {

			var cssRules;
			if (document.all) {
				cssRules = 'rules';
			} else if (document.getElementById) {
				cssRules = 'cssRules';
			}
			
			for (var c=0; c < classArray.length; c++) {
				for (var S = 0; S < document.styleSheets.length; S++){
					for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
						if (document.styleSheets[S][cssRules][R].selectorText == classname) {
							document.styleSheets[S][cssRules][R].style[element] = value;
						}
					}
				}
			}
		}
		
		function debug(message) {
			if (DEBUG_ENABLED)
				alert('Debug: ' + message);
		}
		
		function isArray(tmpArray) {

			if (tmpArray != null && tmpArray.length > 0) {
				return true;
			}

			return false;
		}