function addTextLink()
{

//DEBUG = true;
var $j = jQuery.noConflict();
$j(document).ready(function(){

	var out ='';
	$j("area").each(function(){
		var href= $j(this).attr('href');
		var alt = $j(this).attr('alt');
		out  += '<li><a href="' + href + '">' + alt + '</a>';
//		$j(this).parent().replaceWith('<ul>' + out + '</ul>');
//		alert('<ul>' + out + '</ul>');
	});
	if (out != '' ){
		$j("map").replaceWith('<ul>' + out + '</ul><hr/>');
	};
	
	$j("img").each(function(){
		var alt=$j(this).attr('alt');
		if(alt != 'space' && typeof(alt)!='undefined')
		$j(this).replaceWith(' ' + alt + ' ');
	});
	
	$j("span").each(function(){
		var title=$j(this).attr('title');
		if(typeof(title) != 'undefined')
		$j(this).prepend(title + ' ');
	});	
		
	$j("a").click(function() {
		//get id
		var id=$j(this).attr('id');
		//get url
		var link = escape($j(this).attr('href'));
		//special case skip, and graphics
		if(id=='skip'){return;}
		if(id=='listen_text'){return false;}
		if(id == 'gmode'){
			link = link.replace(/mode%3Dtext/,'');
			link = link.replace(/%3F%26/,'%3F');
			location.href=unescape(link);
			return false;
		}		
		//test url
		var host= new RegExp('^http%3A//(www\.)?sfgov\.org|http%3A//www.ci.sf.ca.us|\^http%3A//'+document.location.hostname);	

		var qmark= new RegExp("^%3F");
		var http = new RegExp("^http%3A//");
		var psign = new RegExp("^%23");
		var dot = /\./;

		if (!(http.test(link) && !(host.test(link))))
		{//internal
			link= link.replace(/^http%3A\/\/[^\/]+/,'');			
			if(!(qmark.test(link)) && !(dot.test(link)) && !(psign.test(link)))
			{//redirect					
			redirect(link);}
			else{
			process(link);	}
		}
		else //external
		{location.href=unescape(link);}
		return false;
	});
});
}

//process internal links add ?mode=text
function process(link)
{
	var mlink = new RegExp("mode%3Dtext");
	var pdf= new RegExp("pdf$|ppt$|doc$");
	var psign = new RegExp("^%23");
	if(!(mlink.test(link)) && !(pdf.test(link)) && !(psign.test(link)))
	{
		var namevalue= link.split("%3F");
		link = namevalue[0] + '%3Fmode%3Dtext';			
		if(namevalue[1]){link = link + '%26' + namevalue[1];}
	}
	location.href=unescape(link);
}

//call redirect to get text only link
function redirect(url)
{
	var request =false;
	try{
		request = new XMLHttpRequest();
	} catch (trymicrosoft){
	     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   } 
   if (!request){return;}
	request.open("GET", url, false);
	request.onreadystatechange = function()
	{	
    if (request.readyState == 4)
	{
		if(request.status == 200)
		{		
			var redir = /<a href="(.*)">Text Only/.exec(request.responseText);
			if(redir){location.href=(redir[1])}
			else{location.href=(url)}
		}
		else{location.href=(url)}
    }
  };
  request.send();
}