//
// File:  revealText.js
// Auth:  Chris Cobb (http://ccobb.net/chris/)
// Date:  24-Apr-2008
// Base:  Based on work by Scott Yang (http://scott.yang.id.au/)
// Date:  04-Jun-2003
// Vers:  0.03
// 
// ------------------------------------------------------------------
// Synopsis of obscuring/revealing an email address:
//
//  <script type='text/javascript' src="/js/revealText.js"></script>
//
//  <script type="text/javascript">
//      Reveal.transmutate(
//            'ROT13_USER',            // Required
//            'ROT13_HOST',            // Required
//            'ROT13_DOMAIN',          // Required
//            'CLEAR_MAIL_OPTS',       // OPTIONAL
//            'CLEAR_HTML_LINK'        // OPTIONAL
//      );
//  </script>
//  <noscript> ALTERNATE_MESSAGE_TEXT </noscript>
//
//
// ------------------------------------------------------------------
// Example of obscuring/revealing an email address:
// 
//  <script type='text/javascript' src="/js/revealText.js"></script>
//
//  Last minute bookings:
//  <script type="text/javascript">
//    Reveal.transmutate('sbb','one','pbz',
//      '?subject=Last%20minute%20booking&body=Greetings,%2C%0D%0AI%20would%20like...',
//      'Contact us for special rates',
//    );
//  </script>
//  <noscript> [To view email link enable JavaScript] </noscript>
//
// ------------------------------------------------------------------
//   

Reveal = {
    map: null,

    convert: function(a) {
        if (Reveal.map == null)
              Reveal.init();

        var s = "";
        for (i=0; i < a.length; i++) {
            var b = a.charAt(i);
            s += ((b>='A' && b<='Z') || (b>='a' && b<='z') ? Reveal.map[b] : b);
        }
        return s;
    },

    init: function() {
        var map = new Array();
        var s   = "abcdefghijklmnopqrstuvwxyz";

        for (i=0; i<s.length; i++)
            map[s.charAt(i)] = s.charAt((i+13)%26);
        for (i=0; i<s.length; i++)
            map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();

        Reveal.map = map;
    },

    transmutate: function(x,y,z,linkopts,linktext) {
        var link = Reveal.convert( x + '@' + y + '.' + z );
	if (linkopts == undefined) {
	    linkopts = "" 
	}
	if (linktext) {
	    document.write('<a href="mailto:' + link + linkopts + '">' 
	        + linktext + '</a>');
	} else {
	    document.write('<a href="mailto:' + link + linkopts + '">' 
	        + link + '</a>');
	}
    },

    write: function(a) {
        document.write(Reveal.convert(a));

    }
}

