
// Replaces all H1 headings with their equivalent graphics

function replace_headings()
{
	var h1_elements = $('right_content').getElementsByTagName('H1');
	for (var i = 0; i < h1_elements.length; i++) { 
		
		var text = h1_elements[i].innerHTML;
		if(text=='') {
			continue;
		}
		h1_elements[i].orig_innerHTML = text;
		//h1_elements[i].innerHTML = '';
		//continue;
		//alert(text);

		new Ajax.Request('main.php', { 
		//	onSuccess : function(resp, jsonObj) { alert(resp.responseText ); },
			onSuccess : 
				function(resp, jsonObj) 
				{
					//alert(resp.responseText);
					/*if (jsonObj.debug) {
						alert(jsonObj.debug);
					}*/
					if(jsonObj.result != 'OK') {
						h1_elements[jsonObj.index].innerHTML = h1_elements[jsonObj.index].orig_innerHTML; 
						//alert(jsonObj.result);
						return;
					}
					
					//alert(jsonObj.heading_image_path);
					h1_elements[jsonObj.index].innerHTML = '<img src="'+jsonObj.heading_image_path+'">';
					
				},
			onFailure : function(resp, jsonObj) {	h1_elements[jsonObj.index].innerHTML = h1_elements[jsonObj.index].orig_innerHTML;   /*alert("There's been an error getting the heading.  Please refresh the page."); */ },
			parameters : "get_heading_image="+encodeURIComponent(text)+"&index="+i } );
	}
}
