		var level1Cutoff = 3;		
		var level2Cutoff = 6;		
		//---
		//var disemvowelledColour = '#707070';
		var disemvowelledColour = '#5c5c5c';
		//var linkColour = '#4246ca';
		var linkColour = '#556eca';
		var openLinkColour = '#03108a';
		//var chevronColour = '#4246ca';
		var chevronColour = openLinkColour;
		//var chevronColour = '#AA0088';
		//---
		var showRatings = 1;

		var wlist = new Object();

		// add a new wordInfo to our list
		function addWord(id, winf)
		{
			winf.domId = id;
			wlist[id] = winf;
		}

		// set the selected word to 'show some' (1)
		function doSome(anId)
		{
			(wlist[anId]).state = 1;
			(wlist[anId]).show();
		}

		// set the selected word to 'show more' (2)
		function doMore(anId)
		{
			(wlist[anId]).state = 2;
			(wlist[anId]).show();
		}

		// set the selected word to 'show all' (3)
		function doAll(anId)
		{
			(wlist[anId]).state = 3;
			(wlist[anId]).show();
		}

		// choose one word to show
		function selectWord(index, anId)
		{
			(wlist[anId]).current = index;

			(wlist[anId]).state = 0;
			(wlist[anId]).show();
		}

		// Show currently selected word
		function selectCurrentWord(anId)
		{
			(wlist[anId]).state = 0;
			(wlist[anId]).show();
		}

		// -----------------------------------------------------------------------
		// wordInfo - holds info about a set of word choices
		//

		// display yourself onto the inner html of the named DOM object
		function show()
		{
			tmpStr = 'undefined';
			switch(this.state)
			{
				case 0:
					tmpStr = this.renderClosed();
					tmpStr = this.fontWrap(tmpStr, linkColour);
					break;
				case 1:
					tmpStr = this.renderSome();
					tmpStr = this.fontWrap(tmpStr, openLinkColour);
					break;
				case 2:
					tmpStr = this.renderMore();
					tmpStr = this.fontWrap(tmpStr, openLinkColour);
					break;
				case 3:
					tmpStr = this.renderAll();
					tmpStr = this.fontWrap(tmpStr, openLinkColour);
					break;
				default:
					break;
			}
			//tmpStr = this.fontWrap(tmpStr, linkColour);
			document.getElementById(this.domId).innerHTML = tmpStr;
		}

		// show yourself in the closed state - only the word indexed at 'current'
		function renderClosed()
		{
			text = '';
			//text += "<span id='" + this.domId + "' onclick=doSome('" + this.domId + "')>";
			text += "<span onclick=doSome('" + this.domId + "')>";
			text += this.words[this.current] + ' ';
			text += '</span>';
			return text;
		}

		// render up to the number of entries passed in
		function rawRender(desiredCount)
		{
			var length = this.words.length;
			var count = Math.min(desiredCount, length)
			var text = this.state + ' ' + '[';
			text += '<font color=' + disemvowelledColour + '>{' + this.baseword + '}</font>&nbsp;';
			//--- Chevron stuff
			if (this.state == 1) 
				{
				// shrink link
				text += "<span onclick=selectCurrentWord('" + this.domId + "')><<</span>";
				// expand link
				if  (length > desiredCount)
					{
					text += "<span onClick=doMore('" + this.domId + "')> <font color=" + chevronColour + ">>></font></span>";
					}
				// expand greyed out
				else	
					{
					text += " <font color=" + disemvowelledColour + ">>></font>";
					}
				}
			if (this.state == 2)
			{
				// contract
				text += "<span onClick=doSome('" + this.domId + "')><font color=" + chevronColour + "><<</font></span> ";

				// expand link
				if (length > desiredCount)
				{
					text += "<span onClick=doAll('" + this.domId + "')> <font color=" + chevronColour + ">>></font></span>";
				}
				// expand greyed out
				else
				{
					text += " <font color=" + disemvowelledColour + ">>></font>";
				}
			}
			if (this.state == 3)
			{
				text += "<span onClick=doMore('" + this.domId + "')><font color=" + chevronColour + "><<</font></span> ";
				text += " <font color=" + disemvowelledColour + ">>></font>";
			}

			//--- Word list
			for (x=0; x<count; x++)
			{
				text += ' ';
				text += "<span onclick=selectWord(" + x + ",'" + this.domId + "')>";
				text += this.words[x];
				if (showRatings == 1)
				{
					text += '<sub>(' + this.ratings[x] + ')</sub>';
				}
				text += "</span>";
				text += ' ';
				if (x < count-1)
				{
					text += '|';
				}
			}
			//---
			text = text + ']&nbsp';
			return(text);
		}

		// show a few entries
		function renderSome()
		{
			return this.rawRender(level1Cutoff);
		}

		// show a few more entries
		function renderMore()
		{
			return this.rawRender(level2Cutoff);
		}

		// show all entries
		function renderAll()
		{
			return this.rawRender(1000);
		}

		// wrap a string in coloured font tags.
		function fontWrap(aStr, aColour)
		{
			return '<font color=' + aColour + '>' + aStr + '</font>';
		}

		// Constructor:
		// - the disemvoweled word we are matching (baseword)
		// - array of words, in order, best to worst score
		// - array of word ratings, matching above
		// - state (int): 0 closed
		// - current word index: which word to show if closed.
		function wordInfo(pbaseword, pwords, pratings, pstate, pcurrent)
		{
			this.baseword=pbaseword;
			this.domId='';
			this.words=pwords;
			this.ratings=pratings;
			this.state=pstate;
			this.current=pcurrent;
			// methods
			this.show=show;
			this.fontWrap=fontWrap;
			this.renderClosed=renderClosed;
			this.renderSome=renderSome;
			this.renderMore=renderMore;
			this.renderAll=renderAll;
			this.rawRender=rawRender;
		}
