/* text extractor */

var textNodes=new Array();

function tn_populate(headNode){
//document.write(headNode.nodeType);
	if(headNode){
		if(headNode.nodeType && headNode.nodeType==3){
			textNodes[textNodes.length]=headNode;
		}
		if(headNode.childNodes){
			for (kid in headNode.childNodes){
				tn_populate(headNode.childNodes[kid]);
			}
		}
	}
}

function tn_graphicize_js(theNode){
	if(!theNode)return false;
	textNodes=new Array();
	tn_populate(theNode);
	var html=''; 
	var nnc='';
	var cc='';
	var rvs=0;
	for (var k=0; k < textNodes.length; k++){
		html = textNodes[k].nodeValue;
		rvs=0;
		if(textNodes[k].parentNode){
		var nt=textNodes[k].parentNode.nodeName.toLowerCase();
		if(
			nt=='a'
			|| nt=='h1'
			|| nt=='h2'
			|| nt=='h3'
			|| nt=='h4'
			|| nt=='h5'
			|| nt=='h6'
			|| nt=='b'
			|| nt=='i'
			|| (textNodes[k].parentNode.getAttribute('class') == 'linky')
		)rvs=1;
		if(nt=='q'){
			nn=document.createElement('span');
			nnt=document.createTextNode(
				String.fromCharCode(34)
				+html
				+String.fromCharCode(34));
			nn.appendChild(nnt);
			textNodes[k].parentNode.parentNode.replaceChild(nn,textNodes[k].parentNode);
			textNodes[k]=nnt;
		}
		nnc='';
		for(var i=0; i < html.length; i++){
			cc=html.charCodeAt(i);
			if(cset[cc]){
				if(rvs==0){
					nnc += '<img src="'+cset[cc]+'" alt="'+html.charAt(i)+'" />';
				}else{
					nnc += '<img src="'+csetrvs[cc]+'" alt="'+html.charAt(i)+'" />';
				}
			}else{
				nnc += html.charAt(i);
			}
		}
		var nn=document.createElement('span');
		
		nn.innerHTML=nnc;
		textNodes[k].parentNode.replaceChild(nn,textNodes[k]);
		}
	}
	return true;
}

function tn_graphicize_css(theNode){
	if(!theNode)return false;
	textNodes=new Array();
	tn_populate(theNode);
	var html=''; 
	var nnc='';
	var cc='';
	var rvs=0;
	for (var k=0; k < textNodes.length; k++){
		html = textNodes[k].nodeValue;
		rvs=0;
		var nt=textNodes[k].parentNode.nodeName.toLowerCase();
		if(
			nt=='a'
			|| nt=='h1'
			|| nt=='h2'
			|| nt=='h3'
			|| nt=='h4'
			|| nt=='h5'
			|| nt=='h6'
			|| nt=='b'
			|| nt=='i'
			|| (textNodes[k].parentNode.getAttribute('class') == 'linky')
		)rvs=1;
		if(nt=='q'){
			nn=document.createElement('span');
			nnt=document.createTextNode(
				String.fromCharCode(34)
				+html
				+String.fromCharCode(34));
			nn.appendChild(nnt);
			textNodes[k].parentNode.parentNode.replaceChild(nn,textNodes[k].parentNode);
			textNodes[k]=nnt;
		}
		nnc='';
		for(var i=0; i < html.length; i++){
			cc=html.charCodeAt(i);
//			if(cset[cc]){
				if(rvs==0){
					nnc += '<img class="gc gc'+cc+'n" src="'+BLANK+'" alt="'+html.charAt(i)+'" />';
				}else{
					nnc += '<img class="gc gc'+cc+'r" src="'+BLANK+'" alt="'+html.charAt(i)+'" />';
				}
//			}else{
//				nnc += html.charAt(i);
//			}
		}
		var nn=document.createElement('span');
		
		nn.innerHTML=nnc;
		textNodes[k].parentNode.replaceChild(nn,textNodes[k]);
	}
	return true;
}

function tn_graphicize_html_js(html){
	var nn=document.createElement('div');
	nn.innerHTML=html;
	tn_graphicize_js(nn);
	return nn;
}

function tn_graphicize_html_css(html){
	var nn=document.createElement('div');
	nn.innerHTML=html;
	tn_graphicize_css(nn);
	return nn;
}
