(function($){ 
   $.fn.extend({
      highlight: function(strings) {

         function findText(node, string, index) {
            if (node.nodeType == 3)
                   return replaceText(node, string, index);
            else if (node.nodeType == 1 && node.childNodes && !(/(script|style)/i.test(node.tagName))) {
                  for (var i = 0; i < node.childNodes.length; ++i) {
                  i += findText(node.childNodes[i], string, index);
                  }
            }
            return 0;
         }
 
         function replaceText(node, string, index){
            var position = replaceSpecialChars(node.data.toUpperCase()).indexOf(string);
               if (position >= 0)
               return highlight(node, position, string, index);
            else
               return 0;
         }
   
         function highlight(node, position, string, index){
            var spannode = document.createElement('span');
            spannode.className = 'highlight highlight-color-'+index;
            var middlebit = node.splitText(position);
            var endbit = middlebit.splitText(string.length);
            var middleclone = middlebit.cloneNode(true);
            spannode.appendChild(middleclone);
            middlebit.parentNode.replaceChild(spannode, middlebit);
            return 1;
         }

         function replaceSpecialChars(s){
            s=s.replace(/(À|Á|Â|Ã|Ä|Å|Æ)/gi,'A');
            s=s.replace(/(È|É|Ê|Ë)/gi,'E');
            s=s.replace(/(Ì|Í|Î|Ï)/gi,'I');
            s=s.replace(/(Ò|Ó|Ô|Ö)/gi,'O');
            s=s.replace(/(Ù|Ú|Û|Ü)/gi,'U');
            s=s.replace(/(Ñ)/gi,'N');
            return s;
         }
 
         return this.each(function() {
            if(typeof strings == 'string')
               findText(this, strings.toUpperCase(), 0); 
            else
               for (var i = 0; i < strings.length; ++i) findText(this, strings[i].toUpperCase(), i);  
         });
      }
   }); 
})(jQuery);
