$(document).ready(function()
  {

  function set_marks(target, pattern, word, linktext, kat, id) {
		  $(target).contents().each(function(node_index, node) {
			  switch(node.nodeType) {
				  case 1:	     
					     set_marks(node, pattern, word, linktext, kat, id);
				  break;
				  case 3:
				     if (node.parentNode.tagName != 'H1' && node.parentNode.tagName != 'H2' && node.parentNode.tagName != 'H3' && node.parentNode.tagName != 'A'){
					     $(node).replaceWith($(node).text().replace(pattern, "<a href='http://www.northern-concepts.de/glossar/"+ kat + "/"+ linktext +"' title='Erkl&auml;rung zu "+ word +"'>" + word + "</a>"));
						 //alert('test');
				     }
				  break;
				  default:
				  break;
			  }
		  });
	  }

 $.post('http://www.northern-concepts.de/includes/parser.php', function(data) {   
	  $(data.begriffe).each(function (i,begriff){		 
		 var inhalt = $("#content");
         set_marks($(inhalt), new RegExp("(" + begriff.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + ")", "gi"), begriff, data.lnk[i], data.kat[i], data.id[i]);
        });						 
  }, 'json');

});




