	
	/*
	JS
	--------------------------------------------------------------------------------------------
	@site			kjetileriksen.no
	@file			Utils.js
	@modifed	01.10.09
	@author		dpaul
	@desc			All purpose utility methods for kjetileriksen.no
	@note			Replaces spam-proof email strings with class of 'mailto' with clickable mailto:links
	@note			(nothing [at] nowhere [dot] com ) 
	@depend	Prototype
	
	/* =:Utils
	--------------------------------------------------------------------------------------------------*/
	if( typeof Kjetileriksen == "undefined" ) var Kjetileriksen = new Object();
	
	Kjetileriksen.Utils = function ()
	{
		/* =:Startup
		  ----------------------------------------------------------------------------------------*/
		function init()
		{
			addEmailLinks();
		}
		
		function addEmailLinks()
		{
			$$('span.mailto').each(function(eml)
			{
				if( eml.hasClassName('custom')){
					var escaped = eml.innerHTML.split(':')[1];
					var phrase = eml.innerHTML.split(':')[0];
					var unescaped = escaped.match(/([^\]]+)\s{1,3}\[at\]\s{1,3}([^\]]+)\s{1,3}\[dot\]\s*([^\]]+)/);
					var proper = unescaped[1]  + '@' +  unescaped[2] + '.'  + unescaped[3];
					var title = eml.readAttribute('title');
					eml.update( '<a href="mailto:'+ proper + '?subject=' + title + '">' + phrase + '</a>' );
				}
				else
				{
					var escaped = eml.innerHTML;
					var unescaped = escaped.match(/([^\]]+)\s{1,3}\[at\]\s{1,3}([^\]]+)\s{1,3}\[dot\]\s*([^\]]+)/);
					var proper = unescaped[1]  + '@' +  unescaped[2] + '.'  + unescaped[3];
					eml.update( '<a href="mailto:'+ proper + '">' + proper + '</a>' );
				}
			});
		}
		
		/* =:Reveal as Public
		  ----------------------------------------------------------------------------------------*/
		return {
			init:init
		}
	
	}();
	
	// Add to onload stack
	document.observe("dom:loaded", function() { 
		Kjetileriksen.Utils.init();
	});	
	

	
