// debugging alerts use # 1 through # 2
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// session constants

var TODAY = new Date();

var CLIENT_PLATFORM = "";
var CLIENT_BROWSER = "";
var CLIENT_BROWSER_VERSION = 0;

var DOC_WIDTH = 790;
var DOC_HEIGHT = 400;

var MIN_TEXT_WIDTH = 200;
var MAX_TEXT_WIDTH = 400;

var MIN_APPLET_WIDTH = 50;
var MAX_APPLET_WIDTH = 5000;

var buttonDetailsDivisionNamePrefix = "jttDetails";

var isContents; // Added by Eric

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// buttons array indices
var iMoleculeFilename = 0;
var iScript = 1;
var iButtonType = 2; // link, button, radio, or checkbox
var iScriptPrefix = 3;
var iButtonLabel = 4;
var iButtonPrefixText = 5;
var iButtonText = 6;
var iScriptCheckboxUnchecked = 7;
var iDetailsText = 8;

// page variables

var text_h = 400;
var text_w = 200;

var jmol_h = 400;
var jmol_w = 400;

var height_offset = 10;
// changing this seems to have no effect whatsoever on div heights

var text_layout = 'left';
var text_color = '000000';
var text_background = 'ffffff';
var text_font = 'verdana';
var text_fontsize = '1em';
var text_fontstyle = 'normal';
var text_fontweight = 'normal';

var jmol_layout = 'right';
var jmol_color = '000000';
var jmol_background = 'ffffff';
var jmol_font = 'courier';
var jmol_fontsize = 12;
var jmol_fontstyle = 'normal';
var jmol_fontweight = 'bold';

var page_title = '';

var nav_location = 'bottom';
var nav_style = 'link';
var nav_contents = '';
var nav_reset = false;
var nav_previous = '';
var nav_next = '';


var buttonNumber = 0;
var buttons = new Array();
buttons[0] = new Array( 'undefined.pdb', '' );


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// the following added by Frieda
// Angel Herraez's code
// for "foolproof" spin toggle that detects spin state and acts accordingly
// Modified by Eric to accomodate later versions of Jmol which message
// the "spin on" in a separate line.

function messageProcess(a_, b_)
{

	// Convert both parameters from Java strings to JavaScript strings:
	// a_ will start with "jmolApplet": strip and leave just the ID part
	var a = (""+a_).substring("jmolApplet".length);
	var b = ""+b_;

	/*  SPIN DETECTION AND TOGGLE */
	var detectShowSpin = "spinFps"; // earlier was "set spin".

	if ( b.indexOf(detectShowSpin) != -1 )
	{
//		alert(b);

		if ( b.indexOf("spin on") != -1 ) //was spinning
			jmolScript("exit; spin off;", a) 

		else //was not spinning
			jmolScript("exit; spin on;", a) 

	}
	/*  END of SPIN DETECTION AND TOGGLE  */
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// functions
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initSessionConstants() {

	if (typeof window.innerWidth != "undefined") {
		DOC_WIDTH = window.innerWidth;
		DOC_HEIGHT = window.innerHeight;
	}

	else if (typeof document.documentElement.offsetWidth != "undefined") {
		DOC_WIDTH = document.documentElement.offsetWidth; 
		DOC_HEIGHT = document.documentElement.offsetHeight; 
	}

	else {
		DOC_WIDTH = document.body.offsetWidth; 
		DOC_HEIGHT = document.body.offsetHeight; 
	}
	
	CLIENT_BROWSER_VERSION = parseFloat(navigator.appVersion);
	
	if ((navigator.appVersion).toLowerCase().indexOf("mac") != -1)
		CLIENT_PLATFORM =  "mac";
	else if ((navigator.appVersion).toLowerCase().indexOf("win") != -1)
		CLIENT_PLATFORM =  "win";
	else 
		CLIENT_PLATFORM =  "other";

	var app = navigator.appVersion.toLowerCase();
	if ((app.indexOf("msie") != -1) || (app.indexOf("explorer") != -1)) 
		CLIENT_BROWSER = "ie";
	else if (app.indexOf("netscape") != -1) CLIENT_BROWSER = "netscape";
	else if (app.indexOf("safari") != -1) CLIENT_BROWSER = "safari";
	else if (app.indexOf("chimera") != -1) CLIENT_BROWSER = "chimera";
	else if (app.indexOf("mozilla") != -1) CLIENT_BROWSER = "mozilla";
	else CLIENT_BROWSER = "unknown";

}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function initPageVariables() {

	DOC_WIDTH = DOC_WIDTH-22;


	text_h = DOC_HEIGHT - 30;
	// original value for this height constant was 20
	// Frieda increased to 50 to make room for control(s) beneath applet
	//IE needs 50; safari only 30; oh well
	// this seems to be the only way to change the height
	// i.e., 'setHeightOffset' in config.js seems to do nothing

	text_w = 0.40 * DOC_WIDTH;
	
	jmol_h = text_h - 20;
	jmol_w = DOC_WIDTH - text_w - 30;
		
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function writeContainerStyle() {
	document.write(
	'<style type="text/css" media="all">' +
	'#container {' +
	'width: ' + (DOC_WIDTH) + 'px;' +
	'background-color: #FFFFFF;' +
	'}' +
	'<\/style>');
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextLayout( side ) {

	if ( side == 'right' ) {
		text_layout = 'right';
		jmol_layout = 'left';
	}
	
	else {
		text_layout = 'left';
		jmol_layout = 'right';
	}

}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextWidth( pct ) {

	text_w = pct * DOC_WIDTH;
	
	if ( text_w < MIN_TEXT_WIDTH ) 
		text_w = MIN_TEXT_WIDTH;
		
	else if ( text_w > MAX_TEXT_WIDTH ) 
		text_w = MAX_TEXT_WIDTH;
	
	jmol_w = DOC_WIDTH - text_w - 25;
	
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setHeightOffset( offset ) {

	height_offset = offset;
	_setAutoHeight();
	
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextFontFace( font ) {
	text_font = font;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextFontSize( sz ) {
	text_fontsize = sz;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextFontStyle( style ) {
	text_fontstyle = style;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextFontWeight( wt ) {
	text_fontweight = wt;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextColor( color ) {
	text_color = color;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextBackground( color ) {
	text_background = color;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextAlinkColor( color ) {
	text_alinkcolor = color;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setTextVlinkColor( color ) {
	text_vlinkcolor = color;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setPageTitle( txt ) {
	page_title = txt;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setNavFontFace( font ) {
	nav_font = font;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setNavFontSize( sz ) {
	nav_fontsize = sz;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setNavFontStyle( style ) {
	nav_fontstyle = style;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setNavFontWeight( wt ) {
	nav_fontweight = wt;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setNavColor( color ) {
	nav_color = color;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setNavBackground( color ) {
	nav_background = color;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setNavigationBar( loc, style ) {
	nav_location = loc;
	nav_style = style;
}
  

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setNavigation( cont, reset, prev, next )
{
	nav_contents = cont;
	nav_reset = reset;
	nav_previous = prev;
	nav_next = next;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setJmolFontFace( font ) {
	jmol_font = font;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setJmolFontSize( sz ) {
	jmol_fontsize = sz;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setJmolFontStyle( style ) {
	jmol_fontstyle = style;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setJmolFontWeight( wt ) {
	jmol_fontweight = wt;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setJmolColor( color ) {
	jmol_color = color;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setJmolBackground( color ) {
	jmol_background = color;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getNavigation() {
	return nav_location;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextHeight() {
	return text_h;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextWidth() {
	return text_w;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextLayout() {
	return text_layout;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextColor( fmt ) {

	if ( !fmt ) 
		var fmt = '';
		
	return _getColor( text_color, fmt );
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextBackground( fmt ) {

	if ( !fmt ) 
		var fmt = '';
		
	return _getColor( text_background, fmt );

}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextFontFace() {
	return text_font;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextFontSize() {
	return text_fontsize;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextFontStyle() {
	return text_fontstyle;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getTextFontWeight() {
	return text_fontweight;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* BEGIN COMMENT OUT

Frieda's failed attempt (so far!) to get link colors 
   into the config. js file:


function getTextAlinkColor() {

	if ( !fmt ) 
		var fmt = '';
		
	return _getColor( text_alinkcolor, fmt );
}

function getTextVlinkColor() {

	if ( !fmt ) 
		var fmt = '';
		
	return _getColor( text_vlinkcolor, fmt );
	
}
END COMMENT OUT */
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function getPageTitle() {
	return page_title;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getNavColor( fmt ) {

	if ( !fmt ) 
		var fmt = '';
		
	return _getColor( nav_color, fmt );
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getNavBackground( fmt ) {

	if ( !fmt ) 
		var fmt = '';
		
	return _getColor( nav_background, fmt );
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getNavFontFace() {
	return nav_font;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getNavFontSize() {
	return nav_fontsize;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getNavFontStyle() {
	return nav_fontstyle;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getNavFontWeight() {
	return nav_fontweight;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getButtonCount()
{
	var count = buttons.length - 1;
//	alert("dvrblite.js #1: getButtonCount() returns " + count);
	return count;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolLayout() {
	return jmol_layout;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolWidth() {
	return jmol_w;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolHeight() {
	return jmol_h;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolColor( fmt ) {
	
	if ( !fmt ) 
		var fmt = '';
		
	return _getColor( jmol_color, fmt );
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolBackground( fmt ) {

	if ( !fmt ) 
		var fmt = '';
		
	return _getColor( jmol_background, fmt );
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolFontFace() {
	return jmol_font;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolFontSize() {
	return jmol_fontsize;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolFontStyle() {
	return jmol_fontstyle;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getJmolFontWeight() {
	return jmol_fontweight;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getResetSpt()
{
// frieda added some commands
	var spt = 'script ../../_sptutil/vreset.spt;';
	
	return spt;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getReorientSpt() {

	var spt = 'reset;';
	return spt;
	
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getDisplaySpt() {

	var spt = 'set specular 5;' + 
	'set ambient 40;' + 
	'set diffuse 75;' + 
	'background ' + getJmolBackground('jmol') + ';' + 
	'font labels ' + getJmolFontSize() + ' ' + getJmolFontFace() + ' ' + getJmolFontWeight() + ';' + 
	'color labels ' + getJmolColor('jmol') + ';' ;
	
	
	// following if statement added by Frieda
	// this is so when a page loads, 
	// the echo "Now Showing View 1" appears in the applet.
	// getDisplaySpt is called whenever a page loads,
	// so it is a good place to add this.
	// BUT on the index (contents) page
	// there is no view 1, just a default view, so we suppress this echo.
	// note var isContents is also used in deciding whether to put a Contents button on the page.
	
	if (!isContents) {

		spt += 'font echo 16 sans bold; color echo [xcccccc]; ' +
		'set echo viewNumber 100% 100%; ' +
		'color echo [xcccccc]; ' +
		'echo Now Showing View 1; ';
	}
	
	return spt;	
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getDefaultSpt() {

	var spt = 'select protein;color chain;backbone 0.5;' + 
	'select nucleic;color cpk;wireframe 0.4;' + 
	'select (a and not backbone);color blue;' + 
	'select (c and not backbone);color red;' + 
	'select (t and not backbone);color yellow;' + 
	'select (g and not backbone);color green;' + 
	'select (u and not backbone);color brown;' + 
	'select (hetero and not solvent);color cpk;wireframe 0.4;spacefill 40%;' + 
	'select solvent;color bluetint;wireframe 0.4;spacefill 40%;';

	return spt;	
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setStart( pdb, spt ) {

	buttons[0][iMoleculeFilename] = pdb;

	if ( !spt ) 
		buttons[0][iScript] = getDefaultSpt();
	else 
		buttons[0][iScript] = spt;
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getStart() {
	var spt = '';
	
	spt += 'load ' + buttons[0][iMoleculeFilename] + ';';
	// frieda removed double quotes because when loading multiple pdb files
	// it is better to put double quotes in original command
	
	spt += getResetSpt();
	spt += getReorientSpt();
	spt += getDisplaySpt();
	spt += buttons[0][iScript];
	
	return spt;	
}

// note 
// num indicates the number of the button that is currently being clicked
// n indicates the number of each button as the buttons were being written
// so when a page is done being written, n = the number of the last button on that page
// and does not change its value again (until next page written)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function makeButton( num )
{
	if (cancelButtonWriting)
		return;

	var bttn = "";

	bttn += '<div class="button">' + buttons[num][iButtonPrefixText];

	// BEGIN spt CONSTRUCTION
	var spt = '';
	var rst = ( buttons[num][iScriptPrefix] ).toLowerCase();
	
	if ( ( rst == 'reset' ) || ( rst == 'y' ) || ( rst == 'yes' ) )
	{
	
		// spt += 'load "' + buttons[num][iMoleculeFilename] + '";';
		// Frieda commented this out  
		// because loading multiple files makes reloading pdb files unnecessary
		// if reinstate, watch out for problems due to quotes

		spt += getResetSpt();
		spt += getReorientSpt();
		spt += getDisplaySpt();
	}

	if ( rst == 'display' ) {
	// frieda added this extra condition to rst
	// it allows instantaneous change of structure, with no change in position
	// instead of structure flashing/repositioning before change appears
	
		spt += getResetSpt();
	}
	
	// added by Frieda
	spt += "set echo viewNumber 100% 100%;\n" +
		"color echo [xcccccc];\n" +
		"echo Now Showing " +	buttons[num][iButtonLabel] + ";" ;
//	alert("dvrblite.js #2: spt = \n" + spt);
	
	spt += buttons[num][iScript];

	// Eric added: When a button is clicked, any still-running script should
	// be unconditionally killed.
	spt = "exit;" + spt;

	// END OF spt CONSTRUCTION
	
	switch ( buttons[num][iButtonType] )
	{
		
		case 'link'		: 
			bttn += jmolLink( spt, buttons[num][iButtonLabel] );
			break;
		
		case 'button'	: 
			bttn += jmolButton( spt, buttons[num][iButtonLabel] );
			break;
		
		case 'radio'	: 
			bttn += jmolRadio( spt, ( '&nbsp;&nbsp;' +
				buttons[num][iButtonLabel] ), false );
			break;
	
		case 'checkbox': 
			bttn += jmolCheckbox( spt, buttons[num][iScriptCheckboxUnchecked],
				( '&nbsp;&nbsp;' +
				buttons[num][iButtonLabel] ), false );
			break;
	}

	bttn += make_script_filename(num);
	
	bttn += '&nbsp;&nbsp;' + buttons[num][iButtonText];

	bttn += makeButtonDetailsControl(num);

	bttn += '<\/div>';

	return bttn;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function makeNavigation()
{
	var writeStr = '';
	
	writeStr += '<p class="nav">';
	
	switch ( nav_style ) {
	
		case 'button'	: 

			// CONTENTS
			if (!isContents && nav_contents != "")
			{
				writeStr += 
				'<input type="button" value="Contents" ' +
				'title="All Chapters" ' +
				'onclick="location.href=\'' + nav_contents + '\'" \/>' +
				'&nbsp;&nbsp;&nbsp;';
			}

			// RESET
			if (!isContents && nav_reset)
			{
				writeStr += 
				'<input type="button" value="Reset View" ' +
				'title="View 1, resetting orientation and zoom" ' +
				'onclick="script2Jmol(\'' + initSpt + '\')" \/>' +
				'&nbsp;&nbsp;&nbsp;';
			}

			writeStr += '&nbsp;&nbsp;&nbsp;';

			// PREVIOUS
			if ( nav_previous != '' )
			{
				writeStr += 
				'<input type="button" value="&lt;- Previous" ' + 
				'title="Previous Chapter" ' +
				'onclick="location.href=\'' + nav_previous + '\'" \/>' + 
				'&nbsp;&nbsp;&nbsp;';
			}

			// NEXT
			if ( nav_next != '' )
			{
				writeStr += 
				'<input type="button" value="Next -&gt;" ' + 
				'title="Next Chapter" ' +
				'onclick="location.href=\'' + nav_next + '\'" \/>';
			}
			
			break;

	// NOTE: CONTENTS AND RESET BUTTONS HAVE NOT YET BEEN IMPLEMENTED
	// FOR THE LINK STYLE.
		case 'link'	: 
			if ( nav_previous != '' ) {
				writeStr += 
				'<a href="' + nav_previous + '" ' + 
				'title="Go back to the previous page.">&lt;- Previous</a>' + 
				'&nbsp;&nbsp;&nbsp;';
			}
			if ( nav_next != '' ) {
				writeStr += 
				'<a href="' + nav_next + '" ' + 
				'title="Go to the next page.">Next -&gt;</a>';
			}
			break;

	}

	writeStr += '<\/p>';

	return writeStr;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function _setAutoHeight() {

	text_h = DOC_HEIGHT - height_offset - 20;
	jmol_h = text_h;
	
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function _getColor( raw, fmt ) {

	//alert( 'getColor with raw=' + raw + ', fmt=' + fmt );
	
	if ( !fmt ) 
		var fmt = '';
		
	var color = raw;
	var word = 0;
	
	if ( color.search( '/[g-zG-Z]/' ) != -1 ) 
		word = 1;
	else 
		word = 0;
		
	switch ( fmt ) {
	
		case 'css'	: 
			if ( !word ) 
				color = '#' + color;
			break;

		case 'html'	: 
			if ( !word ) 
				color = '#' + color;
			break;

		case 'jmol'	: 
			if ( !word ) 
				color = '[x' + color + ']';
			break;

	}
	
	return color;

}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
