// JavaScript Document

/* jQuery plugin: Unobscure Email
   By: Russ Spivey
   
   Description: 
   	Replaces specified DOM element(s) with mailto links. 
   	Parses element text, replaces ' at ' with '@', and removes spaces.
	Maintains element class and id attributes.
   
   Usage example...
   
   html:
   <span class="my_obscured_email">my email at EmilyStrange.com</span>
   
   script:
   $('my_obscured_email').unobscure_email();
   
   resulting html:
   <a href="mailto:myemail@EmilyStrange.com">myemail@EmilyStrange.com</a>
*/

jQuery.fn.unobscure_email = function() {
	return this.each(function(){
		var $this = jQuery(this);
		var saved_classes = $this.attr('class');
		var saved_id = $this.attr('id');
		var my_email = $this.text();
		my_email = my_email.replace(/ at /i,'@');
		my_email = my_email.replace(/ /g,'');
		$this.replaceWith('<a href="mailto:'+my_email+'" id="'+saved_id+'" class="'+saved_classes+'">'+my_email+'</a>');
	});
};
