/*
rotator.js
http://www.josephfinsterwald.com
*/
(function($) {
    $.rotate = function(s) {
        return $.rotate13($.rotate5(s));
    }

    $.rotate5 = function(s) {
        var b = [],c,i = s.length,a = '0'.charCodeAt(),z = a + 10;
        while (i--) { 
            c = s.charCodeAt(i);
            if (c >= a && c < z) { b[i] = String.fromCharCode(((c - a + 5) % (10)) + a); }
            else { b[i] = s.charAt(i); }
        }
        return b.join('');
    };

    $.rotate13 = function(s) {
        var b = [],c,i = s.length,a = 'a'.charCodeAt(),z = a + 26,A = 'A'.charCodeAt(),Z = A + 26;
        while (i--) {
            c = s.charCodeAt(i);
            if (c >= a && c < z) { b[i] = String.fromCharCode(((c - a + 13) % (26)) + a); }
            else if (c >= A && c < Z) { b[i] = String.fromCharCode(((c - A + 13) % (26)) + A); }
            else { b[i] = s.charAt(i); }
        }
        return b.join('');
    };
})(jQuery);
;

(function($){
	$(document).ready(function(){
		$("a.link_and_email_filter-email").each(function(){
			href = $(this).attr('href');
			href_decrypted = decrypt_mailto(href);
			$(this).attr('href', 'mailto:' + href_decrypted);
			$(this).html(href_decrypted);			
		});
	});


	function decrypt_mailto(href) {
	  var address = href.replace(/.*contact\/\?([a-z0-9._%-]+)\+([a-z0-9._%-]+)\+([a-z.]+)/i, '$1' + '@' + '$2' + '.' + '$3');
	  address = $.rotate13(address);
	  return address;
	}


})(jQuery);;

