function copyCode(codeDIV) {
	//there should only be one list under this parent.
	var codeList = codeDIV.getElementsByTagName('ul')[0];

	//if savedList exists, set innerHTML from the PRE version to the list item version
	if (codeDIV.savedList) {
		codeList.innerHTML = codeDIV.savedList;
		codeDIV.savedList = 0;
	} else {
		var code = getCode(codeList.childNodes, 0, '');
		if (code) {
			codeDIV.savedList = codeList.innerHTML;
	
			//replace with string doesn't seem to do < or & characters after the first line.
			code = code.replace(/&/g, '&amp;');
			code = code.replace(/</g, '&lt;');
			code = code.replace(/>/g, '&gt;');

			codeList.innerHTML = '<li class="copyable"><pre>' + code + '</pre></li>';
		}
	}
}


//take a list-oriented HTML display and return indented plain text
function getCode(codeElements, codeDepth, leadingTabs) {
	var subCode = '';
	
	//increase leading tabs if necessary
	if ((codeDepth-1)/2 > leadingTabs.length) {
		leadingTabs = leadingTabs + "\t";
	}

	//loop through each element
	for (var child=0;child<codeElements.length;child++) {
		element = codeElements[child];
		if (element.nodeType == element.TEXT_NODE) {
			//strip white space from text
			var elementText = element.data.replace(/^\s+|\s+$/g,'');
			if (elementText) {
				subCode = subCode + leadingTabs + elementText + "\n";
			}
		} else if (element.tagName != 'SPAN') {
			if (element.className == 'section') {
				subCode = subCode + "\n";
			}
			subCode = subCode + getCode(element.childNodes, codeDepth+1, leadingTabs);
		}
	}

	return subCode;
}
