<!--
function array_search(this_array, this_val) {
	for (var i in this_array) {
		if (this_array[i] == this_val)		return parseInt(i);
	}

	return -1;
}

function scale_word(word, oldSize, oldColor, newSize, newColor, sizeOffset, colorOffset) {
	if ( (oldSize < newSize && oldSize + sizeOffset < newSize) || (oldSize > newSize && oldSize + sizeOffset > newSize) ) {
		thisWord = document.getElementById(word);
		oldSize += sizeOffset;
		oldColor += colorOffset;
		thisWord.style.fontSize = oldSize + "px";
		thisWord.style.color = "rgb(" + oldColor + "," + oldColor + "," + oldColor + ")";

// 					 scale_word(     word,          oldSize,         oldColor,         newSize,         newColor          sizeOffset,         colorOffset)
		thisFunct = "scale_word('" + word + "', " + oldSize + ", " + oldColor + ", " + newSize + ", " + newColor + ", " + sizeOffset + ", " + colorOffset + ")";
		setTimeout(thisFunct, scaling_time);
//	} else if (newSize == 0) {
	} else if (newSize < minFontSize) {
		thisOne = document.getElementById("acro_" + word);
		thisParent = thisOne.parentNode;
		thisParent.removeChild(thisOne);
	} else {
		thisWord = document.getElementById(word);
		oldColor += colorOffset;
		thisWord.style.fontSize = newSize + "px";
		thisWord.style.color = "rgb(" + newColor + "," + newColor + "," + newColor + ")";
	}
}

function change_cloud() {
	lastWord = false;

	if (word_list.length > 0)		old_list = word_list.substr(1, word_list.length-2);
	else							old_list = "";

	// run through frequency_array and compile word_list
	word_list = ",";
	for (word in frequency_array) {
		word_list += word + ",";
	}

	// merge lists together
	overall_array = new Array();
	if (old_list.length > 0) {
		old_array = new Array();
		old_array = old_list.split(",");
		for (i in old_array) {
			overall_array.push(old_array[i]);
		}
	}
	for (word in frequency_array) {
		if ( array_search(overall_array, word) == -1 )
			overall_array.push(word);
	}
	overall_array.sort();

	/****************************************************************************
	*  BEGIN loop over overall_array to remove, grow/shrink, or add
	*****************************************************************************/
	for (var i in overall_array) {
		word = overall_array[i];
		transWord = word.replace(" ", "_");

		if ( word_list.indexOf("," + word + ",") == -1 ) {
			/****************************************************************************
			*  BEGIN removal of old words
			*****************************************************************************/
			acroNode = document.getElementById("acro_" + transWord);
			count = acroNode.getAttribute('title');
			count = count.substr( ("frequency: ").length );
			acroNode.setAttribute('title', 'frequency: waning from ' + count);

			transWord = word.replace(" ", "_");
			thisWord = document.getElementById(transWord);

			oldSize = thisWord.style.fontSize;	oldSize = oldSize.substr(0, oldSize.length-2);
			oldColor = thisWord.style.color;	oldColor = oldColor.substring(4, oldColor.indexOf(","));

			newSize = Math.ceil( oldSize / 2 );
			newColor = Math.ceil( oldColor / 2 );

//			sizeRange = oldSize * -1;
//			colorRange = oldColor - 255;
			sizeRange = newSize - oldSize;
			colorRange = oldColor - newColor;
			colorOffset = Math.ceil( colorRange / (sizeRange / scaling_size) );

// 						 scale_word(         word,           oldSize,         oldColor,  newSize, newColor,sizeOffset,             colorOffset)
//			thisFunct = "scale_word('" + transWord + "', " + oldSize + ", " + oldColor + ", 0, 255, " + (scaling_size*-1) + ", " + colorOffset + ")";
// 						 scale_word(         word,           oldSize,         oldColor,         newSize,         newColor,             sizeOffset,            colorOffset)
			thisFunct = "scale_word('" + transWord + "', " + oldSize + ", " + oldColor + ", " + newSize + ", " + newColor + ", " + (scaling_size*-1) + ", " + colorOffset + ")";
			setTimeout(thisFunct, scaling_time);
			/****************************************************************************
			*  END removal of old words
			*****************************************************************************/
		} else {
			/****************************************************************************
			*  BEGIN loop over frequency_array to grow/shrink if present, add if not
			*****************************************************************************/
			count = frequency_array[word];

			if (count > 0) {
				transWord = word.replace(" ", "_");

				// calculate the font size
				fontOffset = highestCount - lowestCount;
				fontPerc = (count - lowestCount) / fontOffset;
				fontSize = (maxFontSize - minFontSize) * fontPerc + minFontSize;
/*
				// I want the font size to be a sin curve based on the std
				if ( fontSize > variance && fontSize < (variance * 4) ) {
//					fontSize = Math.sin( fontSize * ( (Math.PI / 3) / (variance * 4) ) ) * maxFontSize;
					fontSize = Math.sin( fontSize * ( (Math.PI / 3) / (variance * 8) ) ) * maxFontSize;
				} else if ( fontSize >= (variance*4) ) {
					fontSize = maxFontSize;
				}
*/				fontSize = Math.ceil(fontSize);


				// calculate the color
				colorRange = highestCount - lowestCount;
				colorPerc = (count - lowestCount) / colorRange;
				fontColor = (bright - dark) * colorPerc + dark;
				fontColor = Math.ceil(fontColor);

				// does this one already exist?
				thisWord = document.getElementById(transWord);

				if (thisWord) {
					/****************************************************************
					*  BEGIN grow/shrink
					****************************************************************/
					acroNode = document.getElementById("acro_" + transWord);
					acroNode.setAttribute('title', 'frequency: ' + count);

					oldSize = thisWord.style.fontSize;	oldSize = oldSize.substr(0, oldSize.length-2);
					oldColor = thisWord.style.color;	oldColor = oldColor.substring(4, oldColor.indexOf(","));

					if (oldSize > fontSize)			sizeOffset = scaling_size * -1;
					else							sizeOffset = scaling_size;

					sizeRange = fontSize - oldSize;
					colorRange = fontColor - oldColor;
					colorOffset = Math.ceil( colorRange / (sizeRange / scaling_size) );

					if (oldSize > fontSize)	colorOffset *= -1;
// 								 scale_word(       word,             oldSize,         oldColor,          newSize,         newColor          sizeOffset,         colorOffset)
					thisFunct = "scale_word('" + transWord + "', " + oldSize + ", " + oldColor + ", " + fontSize + ", " + fontColor + ", " + sizeOffset + ", " + colorOffset + ")";
					setTimeout(thisFunct, scaling_time);
					/****************************************************************
					*  END grow/shrink
					****************************************************************/
				} else {
					/****************************************************************
					*  BEGIN add
					****************************************************************/

					// pull the display out of the slider display
					display = document.getElementById('date_display');
					this_date = display.value;
	
					// get date format from this
					this_date = getDateFromText(this_date);

					// create it
//					acroNode = document.createElement('acronym');
					acroNode = document.createElement('a');
					acroNode.setAttribute('href', '../term_highlight.php?term=' + word + '&date=' + this_date);
					acroNode.setAttribute('target', '_blank');
					acroNode.setAttribute('id', 'acro_' + transWord);
					acroNode.setAttribute('class', 'wordclass');
					acroNode.setAttribute('className', 'wordclass');
					acroNode.setAttribute('title', 'frequency: ' + count);
					acroNode.setAttribute('style', 'margin: 0px ' + minFontSize + 'px');

					thisWord = document.createElement('span');
					thisWord.setAttribute('id', word.replace(" ", "_") );
					thisWord.style.fontSize = "1px";
					thisWord.style.color = "rgb(" + dark + "," + dark + "," + dark + ")";

					wordNode = document.createTextNode(word);
					crNode = document.createTextNode("\n");
					cloudNode = document.getElementById("cloud_box");

					thisWord.appendChild(wordNode);
					thisWord.appendChild(crNode);
					acroNode.appendChild(thisWord);

					if (lastWord == false) {
						cloudNode.appendChild(acroNode);
						cloudNode.insertBefore(acroNode, cloudNode.firstChild);
					} else {
						lastAcro = document.getElementById("acro_" + lastWord);
						cloudNode.insertBefore(acroNode, lastAcro.nextSibling);
					}
			
					sizeRange = fontSize - 1;
					colorRange = fontColor - dark;
					colorOffset = Math.ceil( colorRange / (sizeRange / scaling_size) );
//	 							 scale_word(       word,       oldSize,oldColor,      newSize,         newColor             sizeOffset,          colorOffset)
					thisFunct = "scale_word('" + transWord + "', 1, " + dark + ", " + fontSize + ", " + fontColor + ", " + scaling_size + ", " + colorOffset + ")";
					//alert(thisFunct);
					setTimeout(thisFunct, scaling_time);

					/****************************************************************
					*  END add
					****************************************************************/
				}
			}
		}
		lastWord = transWord;
	}
	/****************************************************************************
	*  END loop over frequency_array to grow/shrink if present, add if not
	*****************************************************************************/

	// now run through all words and remove ones that aren't in overall_array at all, 
	// left over from sliding the slider faster than the JS could keep up
	words = carpeGetElementsByClass('wordclass'); // Find the horizontal sliders.
	for (i = 0; i < words.length; i++) {
		this_node = words[i].id;
		this_word = this_node.substr(5);
		this_word = this_word.replace("_", " ");
		if (array_search(overall_array, this_word) == -1) {
			thisParent = words[i].parentNode;
			thisParent.removeChild(words[i]);
		}
	}
}

function changeDate(this_date) {
	if (!xmlhttp) {
		alert("I'm sorry, this requires an AJAX-compatible browser.");
	} else {
		if ( this_date.substr( this_date.length-1 ) == "_" ) {
			url = cache_dir + "/" + this_date.substr(0, 5) + this_date.substr(6, 1) + "_terms-20.txt";
		} else {
			url = cache_dir + "/" + this_date + "_terms-20.txt";
		}
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
//				alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				change_cloud();
			}
		}
		xmlhttp.send(null)
	}
}

//-->