	// Globals variables //
	var _currentPatternColorID = 0, _currentPatternDefinitionID = 0, _stop = 1, _dragHandle = "", _dragHandleStyle, tX, tY, HSV = {0 : 360,1 : 0,2 : 100}, hSV = 149, wSV = 140;
	var _hueTrackHeight = 147, _clickMouseLocale = "", _refreshTimeout = 0, _lastRefreshState = [], _canShowFCP = true, _patternAssignmentBackreference = "";
	var _basicLimits = {"basicHex": [0,16777215],"basicR": [0,255],"basicG": [0,255],"basicB": [0,255],"basicH": [0,359],"basicS": [0,100],"basicV": [0,100],"basicC": [0,100],"basicM": [0,100],"basicY": [0,100],"basicK": [0,100]};

	initFCP = function() {
		addEvent(onLoadFCP,"load");
	}

	onLoadFCP = function() {
		if ($("basicHex") && $("basicR") && $("basicG")) {
			document.onmousemove = fCPMouseHandlerOnMouseMove;
			document.onmouseup = fCPMouseHandlerOnMouseUp;
			document.onmousedown = fCPMouseHandlerOnMouseDown;

			["basicHex","basicR","basicG","basicB","basicH","basicS","basicV","basicC","basicM","basicY","basicK"].each(function(_elementID) {
				if (["basicC","basicM","basicY","basicK"].in_array(_elementID) == false) {
					$(_elementID).onblur = $(_elementID).onkeyup = function(_event) {
						_event = domEvent(_event);
						updateBasicFromForm(_event,_event.target.id,true);
					}
				}

				$(_elementID).onkeydown = function(_event) {
					_event = domEvent(_event);
					var _val = $(_event.target.id).value;
					if ([40,38].in_array(_event.code)) {
						_val = (_event.target.id == "basicHex") ? hex2dec(_val) : parseInt(_val);
						(_event.code == 40) ? ((within(--_val,_basicLimits[_event.target.id][0],_basicLimits[_event.target.id][1])) ? "" : _val++) : ((within(++_val,_basicLimits[_event.target.id][0],_basicLimits[_event.target.id][1])) ? "" : _val--);
						_val = (_event.target.id == "basicHex") ? dec2hex(_val).toString().padHex() : _val;
						$(_event.target.id).value = _val;
					}
					if ([13,40,38].in_array(_event.code)) {
						updateBasicFromForm(_event,_event.target.id);
					}
				}
			});
			if (["patterns/add","patterns/mod"].in_array(_currentPage)) {
				_lastRefreshState = eval(_patternAssignmentBackreference)._colorHexs.clone();
			}
		}
	}

	var _Pattern = function(_assignmentBackreference) {
		_patternAssignmentBackreference = _assignmentBackreference;
		return {
			__constructor: function() {
				$R(0,4).each(function(_i) {
					$("newColourName" + _i).onkeyup = $("newColourName" + _i).onblur = $("newColourName" + _i).onchange = function() {
						eval(_patternAssignmentBackreference).updateColorName(_i,this);
					}
				});
			}(),

			_colorHexs: ["","","","",""],
			_colorNames: new Hash({}),
			_colorHexsNotInSystem: [], // 0-based && sequential
			_colorHexsHaveBeenChecked: false,
			_checkIfColorsExistRequestResponse: "",
			checkIfColorsExistRequest: function() {
				if (this._colorHexs.length >= 2) {
					buildRequest("checkIfColoursExist",[this._colorHexs.implode("|"),"n"]);
				} else {
					alert("Patterns need two or more colors!");
				}
				return false;
			},
			checkIfColorsExistRequestResponse: function(_responseText,_colorHexsNotInSystemResponse) {
				var _i;
				this._checkIfColorsExistRequestResponse = _responseText;
				this._colorHexsHaveBeenChecked = true;

				if (this._checkIfColorsExistRequestResponse != "nc") {
					this._colorHexsNotInSystem = this._checkIfColorsExistRequestResponse.split("|");
					for (_i=0;_i<this._colorHexsNotInSystem.length;_i++) {
						if (![undefined,""].in_array(this._colorNames.get(this._colorHexsNotInSystem[_i]))) {
							// If we get here, the hex at hand "this._colorHexsNotInSystem[_i]" has been named, so we consider it in the system and remove from the check array
							this._colorHexsNotInSystem[_i] = undefined;
						}
					}
					this._colorHexsNotInSystem = this._colorHexsNotInSystem.compact();
				} else {
					this._colorHexsNotInSystem = [];
				}
				this.updateNameFields(true,true);
				this.debug("checkIfColorsExistRequestResponse");
			},
			updateNameFields: function(_showAlert,_readySubmit) {
				var _colorsAlreadyShown = [], _i, _j, _tmpName = "";
				// Hide all the name fields and set their values to this._colorNames [which might have been re-ordered]:
				hideNewColourDivs();
				for (_i=0;_i<5;_i++) {
					_tmpName = this._colorNames.get(this._colorHexs[_i]);
					$("newColourName" + this._colorHexs.indexOf(this._colorHexs[_i])).value = ((_tmpName == undefined) ? "" : _tmpName);
				}

				if (this._colorHexsNotInSystem.length != 0) {
					for (_i=0;_i<5;_i++) {
						if (this._colorHexsNotInSystem.in_array(this._colorHexs[_i])) {
							$S("cNotice").display = "block";
							$S("newColourDiv" + this._colorHexs.indexOf(this._colorHexs[_i])).display = "block";
						}
					}
					if (_showAlert) {
						alert("Please name these colors to add them now.");
					}
				} else if (_readySubmit) {
					var _ov = new objectVerify();
					_ov.addElement("patternTitle");

					if (verifyByObject(_ov,"Please wait ...","submitBtn")) {
						$("patternData").value = Object.toJSON(this);
						$("addPatternForm").submit();
						return true;
					}
				}
				this.debug("updateNameFields");
			},
			updateColorName: function(_colorIndex,_element) {
				this._colorNames.set(this._colorHexs[_colorIndex],_element.value.toString().strip());
				this.debug("updateColorName");
			},
			updateInternalColorList: function(_colorIndex,_colorHex) {
				var _order = Sortable.sequence("patternColorsList"), _tmpColorHexs = [], _i;
				Sortable.setSequence("patternColorsList",[0,1,2,3,4]);

				if ((_colorIndex != undefined) && (_colorHex != undefined)) {
					this._colorHexs[_colorIndex] = _colorHex;
					this._colorHexsHaveBeenChecked = false;
				}

				// Update the order
				for (_i=0;_i<this._colorHexs.length;_i++) {
					_tmpColorHexs.push(this._colorHexs[_order[_i]].toUpperCase());
				}
				this._colorHexs = _tmpColorHexs.clone();
				this.updateNameFields(false,false);

				// Prevent the FCP from showing up when rearranging the colors
				_canShowFCP = false;
				refreshPattern();
				this.debug("updateInternalColorList");
			},
			updateHTMLColorList: function() {
				for (_i=0;_i<this._colorHexs.length;_i++) {
					$S("newColourTD" + _i).backgroundColor = $S("patternColorSquare_" + _i).backgroundColor = ("#" + this._colorHexs[_i]);
				}
				this.debug("updateHTMLColorList");
			},
			saveForLater: function() {
				$("patternData").value = Object.toJSON(this);
				$("addPatternForm").submit();
				return true;
				this.debug("saveForLater");
			},
			debug: function(_from) {
				//$("inspectDiv").innerHTML = "<b>From:</b> " + _from + " " + (new Date()).getTime() + "<br /><b>_colorHexs:</b> <span style=\"font-family: courier new;\">" + this._colorHexs + "</span><br /><b>_colorNames:</b> " + this._colorNames.toJSON() + "</span><br /><b>_colorHexsNotInSystem:</b> " + this._colorHexsNotInSystem;
			}
		};
	}

	fCPMouseHandlerOnMouseMove = function(_event) {
		var _scrollTop = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		var _scrollLeft = (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;

		_event = (_event) ? _event : event;
		_mouseCoords = (document.all) ? [event.clientX + _scrollLeft,event.clientY + _scrollTop] : [_event.pageX,_event.pageY];

		if (_clickMouseLocale == "fCPPicker") {
			dragFCP(_event);
		}
	}

	fCPMouseHandlerOnMouseUp = function(_event) {
		document.onselectstart = function() {
			return true;
		}

		if (_clickMouseLocale == "fCPPicker") {
			_stop = 1;
			if (["patterns/add","patterns/mod"].in_array(_currentPage)) {
				refreshPattern();
			}
		}
		if ($("pageIsCreateModPalette")) {
			_refreshTimeout = setTimeout("newColours()",200);
		}
	}

	fCPMouseHandlerOnMouseDown = function() {
		if (_clickMouseLocale == "fCPPicker") {
			document.onselectstart = function() {
				return false;
			}
		}
		if ($("pageIsCreateModPalette")) {
			clearTimeout(_refreshTimeout);
		}
	}

	searchPatternCategories = function() {
		buildRequest("patternCategorySearchResponse",[$("patternCategoryID").options[$("patternCategoryID").selectedIndex].value,$("patternCategoryOrderBy").options[$("patternCategoryOrderBy").selectedIndex].value,0])
	}

	refreshPattern = function() {
		// Don't update this if we don't have to:
		if (_lastRefreshState.toString() != eval(_patternAssignmentBackreference)._colorHexs.toString()) {
			try {
				clearTimeout(_refreshTimeout);
			} catch (_e) {}
			_refreshTimeout = setTimeout("refreshPatternLiaison()",1000);
			_lastRefreshState = eval(_patternAssignmentBackreference)._colorHexs.clone();
		}
	}

	refreshPatternLiaison = function() {
		if ($("patternPreviewDiv")) {
			$S("patternPreviewDiv").backgroundImage = "url(/patternPreview/" + _currentPatternDefinitionID + "/" + eval(_patternAssignmentBackreference)._colorHexs.implode("/") + ".png)";
		}
	}

	selectNewPatternDefinitionID = function(_patternDefinitionID,_numColors,_newTitles) {
		if (_patternDefinitionID != _currentPatternDefinitionID) {
			_newTitles = _newTitles.split("|");
			clearTimeout(_refreshTimeout);
			$("patternDefinitionID").value = _currentPatternDefinitionID = _patternDefinitionID;
			// Avoid the last refresh state check:
			_refreshTimeout = setTimeout("refreshPatternLiaison()",1000);

			for (_i=0;_i<5;_i++) {
				if (_i < _numColors) {
					$S("patternColorSquare_" + _i).display = "block";
					$S("patternColorSquareLi_" + _i).display = "block";
					$S("patternColorSquareText_" + _i).display = "block";
					$("patternColorSquareText_" + _i).innerHTML = _newTitles[_i];
				} else {
					$S("patternColorSquare_" + _i).display = "none";
					$S("patternColorSquareLi_" + _i).display = "none";
					$S("patternColorSquareText_" + _i).display = "none";
					$("patternColorSquareText_" + _i).innerHTML = "";
				}
			}
		}
	}

	hideNewColourDivs = function() {
		$S("cNotice").display = "none";
		for (_i=0;_i<5;_i++) {
			$S("newColourDiv" + _i).display = "none";
		}
	}

	agent = function(_agent) {
		return Math.max(navigator.userAgent.toLowerCase().indexOf(_agent),0);
	}

	transparentBGOnKeyUp = function(_hex) {
		if (isHex(_hex)) {
			$("basicHex").value = _hex;
			updateBasicFromForm("","basicHex");
		}
	}

	showFCPPalettes = function(_tBGHex) {
		var _pos = absPos($("transparentBG"));
		$S("fCP").left = ((_pos.x - 35) + "px");
		$S("fCP").top = ((_pos.y + 30) + "px");
		$S("fCP").display = "block";
	}

	showFCP = function(_colorID) {
		if (_canShowFCP) {
			_currentPatternColorID = _colorID;
			var _pos = absPos($("patternColorSquareLi_" + _currentPatternColorID));
			$S("fCP").left = ((_pos.x + 60) + "px");
			$S("fCP").top = ((_pos.y - 100) + "px");
			$S("fCP").display = "block";
			$("basicHex").value = eval(_patternAssignmentBackreference)._colorHexs[_currentPatternColorID];
			updateBasicFromForm("","basicHex");
		}
	}

	hideFPC = function() {
		$S("fCP").display = "none";
	}

	fCPslide = function(_dH,_object,_event) {
		_clickMouseLocale = "fCPPicker";
		if (_stop) {
			_stop = 0; // was ""

			_dragHandleStyle = $S(_dH);
			_dragHandle = _dH;
			_absolutePosition = absPos($(_object)), tX, tY;
			_absolutePosition.x += 7;
			_absolutePosition.y += 7;

			dragFCP(_event);
		}
	}

	XY = function(_event) {
		var _scrollTop = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		var _scrollLeft = (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		return agent("msie") ? [event.clientX + _scrollLeft,event.clientY + _scrollTop] : [_event.pageX,_event.pageY];
	}

	tXY = function(_event) {
		tY = XY(_event)[1] - _absolutePosition.y;
		tX = XY(_event)[0] - _absolutePosition.x;
	}

	ckHSV = function(a,b,_dragHandle) {
		if (within(a,0,b)) {
			return a;
		} else if (a > b) {
			return b;
		} else if (a < 0) {
			if (_dragHandle == "basicSatValSlide") {
				return -3;
			} else {
				return -4;
			}
		}
	}

	within = function(_val,_low,_high) {
		return ((_val >= _low) && (_val <= _high));
	}

	mkHSV = function(a,b,c) {
		return Math.min(a,Math.max(0,Math.ceil((parseInt(c) / b) * a)));
	}

	dragFCP = function(_event) {
		_event = (!_event) ? window.event : _event;
		if (!_stop) {
			tXY(_event);

			clearTimeout(_refreshTimeout);
			if (_dragHandle == "fCPSatValSlide") {
				_dragHandleStyle.left = ckHSV(tX,wSV,_dragHandle) + "px";
				_dragHandleStyle.top = ckHSV(tY,wSV,_dragHandle) + "px";

				$S("fCPSatSlide").top = Math.floor((ckHSV(tX,wSV,"fCPSatValSlide") / wSV) * _hueTrackHeight) + "px";
				$S("fCPValSlide").top = Math.floor((ckHSV(tY,wSV,"fCPSatValSlide") / wSV) * _hueTrackHeight) + "px";
				HSV[1] = mkHSV(100,wSV,_dragHandleStyle.left);
				HSV[2] = 100 - mkHSV(100,wSV,_dragHandleStyle.top);
			} else if (_dragHandle == "fCPHueSlide") {
				var ck = ckHSV(tY,_hueTrackHeight,_dragHandle);
				_dragHandleStyle.top = (ck + "px");
				HSV[0] = mkHSV(360,_hueTrackHeight,ck);
			} else if (_dragHandle == "fCPSatSlide") {
				var ck = ckHSV(tY,_hueTrackHeight,_dragHandle);
				_dragHandleStyle.top = (ck + "px");
				$S("fCPSatValSlide").left = Math.floor((ckHSV(tY,_hueTrackHeight,"fCPSatValSlide") / _hueTrackHeight) * wSV) + "px";
				HSV[1] = mkHSV(100,_hueTrackHeight,ck);
			} else if (_dragHandle == "fCPValSlide") {
				var ck = ckHSV(tY,_hueTrackHeight,_dragHandle);
				_dragHandleStyle.top = (ck + "px");
				$S("fCPSatValSlide").top = Math.floor((ckHSV(tY,_hueTrackHeight,"fCPSatValSlide") / _hueTrackHeight) * wSV) + "px";
				HSV[2] = 100 - mkHSV(100,_hueTrackHeight,ck);
			}

			$S("fCPSatVal").backgroundColor = $S("fCPSat").backgroundColor = $S("fCPVal").backgroundColor = ("#" + hsv2hex([HSV[0],100,100]));
			var _tmp = hsv2hex(HSV);

			// Palette Search
			if ($("transparentBG")) {
				$S("transparentBG").background = ""; // Clear out img
				$S("transparentBG").backgroundColor = ("#" + _tmp);
				$("hex").value = _tmp;
			}

			// Create / Mod Palette && Create / Mod Color
			if ($("pageIsCreateModPalette") || $("pageIsCreateModColor")) {
				updateHexDiv(_tmp);
			}

			if (["patterns/add","patterns/mod"].in_array(_currentPage)) {
				eval(_patternAssignmentBackreference).updateInternalColorList(_currentPatternColorID,_tmp);
				eval(_patternAssignmentBackreference).updateHTMLColorList();
			}
			updateBasicFormElements();
		}
	}

	updateBasicFormElements = function(_except) {
		if (_except != "basicHex") {
			$("basicHex").value = hsv2hex(HSV);
		}

		var _rgb = hsv2rgb(HSV);
		if (_except != "basicR") {
			$("basicR").value = parseInt(_rgb[0]);
		}
		if (_except != "basicG") {
			$("basicG").value = parseInt(_rgb[1]);
		}
		if (_except != "basicB") {
			$("basicB").value = parseInt(_rgb[2]);
		}

		if (_except != "basicH") {
			$("basicH").value = parseInt(HSV[0]);
		}
		if (_except != "basicS") {
			$("basicS").value = parseInt(HSV[1]);
		}
		if (_except != "basicV") {
			$("basicV").value = parseInt(HSV[2]);
		}

		var _cmyk = rgb2cmyk(hsv2rgb(HSV));
		if (_except != "basicC") {
			$("basicC").value = parseInt(_cmyk[0]);
		}
		if (_except != "basicM") {
			$("basicM").value = parseInt(_cmyk[1]);
		}
		if (_except != "basicY") {
			$("basicY").value = parseInt(_cmyk[2]);
		}
		if (_except != "basicK") {
			$("basicK").value = parseInt(_cmyk[3]);
		}
	}

	updateBasicFromForm = function(_event,_elementID) {
		if (_elementID == "") {
			_event = (_event) ? _event : window.event;
			if (_event.srcElement) {
				_event.target = _event.srcElement;
			}
			var _id = _event.target.id;
		} else {
			var _id = _elementID;
		}
		var _val = $(_id).value, _canUpdate = false, _skipHSV = false;

		if (_id == "basicHex") {
			if (isHex(_val)) {
				HSV = rgb2hsv(hex2rgb(_val));
				_canUpdate = true, _skipHSV = true;
			}
		} else if (_id == "basicR") {
			_val = parseInt(_val);
			if (within(_val,0,255)) {
				var _rgb = hsv2rgb(HSV);
				HSV = rgb2hsv([_val,_rgb[1],_rgb[2]]);
				_canUpdate = true;
			}
		} else if (_id == "basicG") {
			_val = parseInt(_val);
			if (within(_val,0,255)) {
				var _rgb = hsv2rgb(HSV);
				HSV = rgb2hsv([_rgb[0],_val,_rgb[2]]);
				_canUpdate = true;
			}
		} else if (_id == "basicB") {
			_val = parseInt(_val);
			if (within(_val,0,255)) {
				var _rgb = hsv2rgb(HSV);
				HSV = rgb2hsv([_rgb[0],_rgb[1],_val]);
				_canUpdate = true;
			}
		} else if (_id == "basicH") {
			_val = parseInt(_val);
			if (within(_val,0,360)) {
				HSV = [_val,HSV[1],HSV[2]]
				_canUpdate = true;
			}
		} else if (_id == "basicS") {
			_val = parseInt(_val);
			if (within(_val,0,360)) {
				HSV = [HSV[0],_val,HSV[2]]
				_canUpdate = true;
			}
		} else if (_id == "basicV") {
			_val = parseInt(_val);
			if (within(_val,0,360)) {
				HSV = [HSV[0],HSV[1],_val]
				_canUpdate = true;
			}
		} else if ((_id == "basicC") || (_id == "basicM") || (_id == "basicY") || (_id == "basicK")) {
			_c = parseInt($("basicC").value);
			_m = parseInt($("basicM").value);
			_y = parseInt($("basicY").value);
			_k = parseInt($("basicK").value);

			if (_id == "basicC") {
				_c = (within(_c,0,100)) ? _c : 0;
			} else if (_id == "basicM") {
				_m = (within(_m,0,100)) ? _m : 0;
			} else if (_id == "basicY") {
				_y = (within(_y,0,100)) ? _y : 0;
			} else if (_id == "basicK") {
				_k = (within(_k,0,100)) ? _k : 0;
			}
			HSV = rgb2hsv(cmyk2rgb([_c,_m,_y,_k]));
			_canUpdate = true;
		}

		if (_canUpdate) {
			var _hueSliderY = h2y(HSV[0]);
			var _satSliderY = s2y(HSV[1]);
			var _valSliderY = v2y(HSV[2]);

			$S("fCPHueSlide").top = Math.floor(ckHSV((_hueSliderY - 3),_hueTrackHeight + 3,"fCPHueSlide")) + "px";
			$S("fCPSatSlide").top = Math.floor(ckHSV((_satSliderY - 3),_hueTrackHeight + 3,"fCPSatSlide")) + "px";
			$S("fCPValSlide").top = Math.floor(ckHSV((_valSliderY - 3),_hueTrackHeight + 3,"fCPValSlide")) + "px";

			$S("fCPSatValSlide").left = Math.ceil(ckHSV((_satSliderY - 7),wSV,"fCPSatValSlide")) + "px";
			$S("fCPSatValSlide").top = Math.ceil(ckHSV((_valSliderY - 7),wSV,"fCPSatValSlide")) + "px";
			$S("fCPSatVal").backgroundColor = $S("fCPSat").backgroundColor = $S("fCPVal").backgroundColor = ("#" + hsv2hex([HSV[0],100,100]));
			var _tmp = (_skipHSV == false) ? hsv2hex(HSV) : _val;

			// Palette Search
			if ($("transparentBG")) {
				$S("transparentBG").background = ""; // Clear out img
				$S("transparentBG").backgroundColor = ("#" + _tmp);
				$("hex").value = _tmp;
			}

			// Create Palette
			if ($("pageIsCreateModPalette") || $("pageIsCreateModColor")) {
				updateHexDiv(_tmp);
			}

			if (["patterns/add","patterns/mod"].in_array(_currentPage)) {
				eval(_patternAssignmentBackreference).updateInternalColorList(_currentPatternColorID,_tmp);
				eval(_patternAssignmentBackreference).updateHTMLColorList();
			}
			updateBasicFormElements(_id);
		}
	}


	/* CONVERSIONS */
	h2y = function(_hue) {
		return ((_hue / 360) * _hueTrackHeight);
	}

	s2y = function(_satVal) {
		return ((_satVal / 100) * _hueTrackHeight);
	}

	v2y = function(_valVal) {
		return (Math.abs(((_valVal / 100) * (_hueTrackHeight + 3)) - _hueTrackHeight - 3));
	}

	hsv2hex = function(h) {
		return rgb2hex(hsv2rgb(h));
	}
	toHex = function(v) {
		v=Math.round(Math.min(Math.max(0,v),255)); return("0123456789ABCDEF".charAt((v-v%16)/16)+"0123456789ABCDEF".charAt(v%16));
	}
	hex2rgb = function(r) {
		return({0:parseInt(r.substr(0,2),16),1:parseInt(r.substr(2,2),16),2:parseInt(r.substr(4,2),16)});
	}
	rgb2hex = function(r) {
		return(toHex(r[0])+toHex(r[1])+toHex(r[2]));
	}
	rgb2hsv = function(r) {
		var max=Math.max(r[0],r[1],r[2]), delta=max-Math.min(r[0],r[1],r[2]), H, S, V;
		if(max!=0) {
			S=Math.round(delta/max*100);
			if(r[0]==max) H=(r[1]-r[2])/delta; else if(r[1]==max) H=2+(r[2]-r[0])/delta; else if(r[2]==max) H=4+(r[0]-r[1])/delta; var H=Math.min(Math.round(H*60),360); if(H<0) H+=360;
		}
		return({0:H?H:0,1:S?S:0,2:Math.round((max/255)*100)});
	}
	hsv2rgb = function(r) {
		var F, R, B, G, H=r[0]/360, S=r[1]/100, V=r[2]/100;
		if(S>0) {
			if(H>=1) H=0;
			H=6*H; F=H-Math.floor(H); A=Math.round(255*V*(1-S)); B=Math.round(255*V*(1-(S*F))); C=Math.round(255*V*(1-(S*(1-F)))); V=Math.round(255*V);
			switch(Math.floor(H)) {
				case 0: R=V; G=C; B=A; break;
				case 1: R=B; G=V; B=A; break;
				case 2: R=A; G=V; B=C; break;
				case 3: R=A; G=B; B=V; break;
				case 4: R=C; G=A; B=V; break;
				case 5: R=V; G=A; B=B; break;
			}
			return([R?R:0,G?G:0,B?B:0]);
		}
		else return([(V=Math.round(V*255)),V,V]);
	}
	rgb2cmyk = function(r) {
		var C=1-(r[0]/255), M=1-(r[1]/255), Y=1-(r[2]/255), K=Math.min(Y,Math.min(M,Math.min(C,1)));
		C=Math.round((C-K)/(1-K)*100); M=Math.round((M-K)/(1-K)*100); Y=Math.round((Y-K)/(1-K)*100); K=Math.round(K*100);
		return([C?C:0,M?M:0,Y?Y:0,K]);
	}
	cmyk2rgb = function(r) {
		r[3]=r[3]/100; var R=(1-(r[0]/100*(1-r[3])+r[3]))*255, G=(1-(r[1]/100*(1-r[3])+r[3]))*255, B=(1-(r[2]/100*(1-r[3])+r[3]))*255;
		return([R,G,B]);
	}
	websafe = function(r) { var s=$("mode").selectedIndex;
		if(s) var n=(s==2?51:17), z=[Math.round(r[0]/n)*n,Math.round(r[1]/n)*n,Math.round(r[2]/n)*n];
		return(rgb2hex(z?z:r));
	}
	rgba = function(r,v) { return('rgba('+r[0]+','+r[1]+','+r[2]+','+(v?v:(isNaN(r[3])?1:r[3]))+')'); }
	round = function(v) { return(Math.round(parseFloat(v)*100000)/100000); }

	initFCP();