/**
 * replaces rollmop substitute, such as [at], :at: with @
 */

(function($){
  '$:nomunge'; // Used by YUI compressor.
  
  $.fn.replaceMailAt = function(at_symbol) {
    return this.each(function(){
      var node = this.firstChild,
        val,
        new_val,        
        remove = [];
      if (node) { //all children
        do {
          if(node.nodeType === 1) { //hrefs
        	  val = node.getAttribute('href');
        	  if(val) {
        		  new_val = val.replace(at_symbol,'@');
        		  if(new_val !== val) node.setAttribute('href', new_val);
        	  }
        	    
          }
        	
          if(node.nodeType === 3) { //text nodes
            val = node.nodeValue;
            new_val = val.replace(at_symbol, '@');
            if (new_val !== val) {
              
              if (/</.test(new_val)) { //contains HTML
                $(node).before(new_val);
                remove.push(node);
              } else {
                node.nodeValue = new_val;
              }
            }
          }
        } while ( node = node.nextSibling );
      }
      remove.length && $(remove).remove();
    });
  };  
  
})(jQuery);

$(document).ready(function(){
	$('body *').replaceMailAt(/\[:zav:\]/gi);
});
