var Utils = {
	
	/*
		Function: fire
			Fires a custom event with *document* as the target. All custom event names must be namespaced (using a colon)!
			Wrapper for the Prototype's *document.fire* method (<http://api.prototypejs.org/dom/document/fire/>).
			
		Parameters:
			- eventName 	:	(string) the name of the event to fire
			- memo			: 	(object) information data assigned to the memo property of the event object so that it can be read by event handlers
	*/
	fire : function(eventName, memo) {
		// Delegate:
		document.fire(eventName, memo);
	},
	
	/*
		Function: observe
			Starts observing the given event on *document* object and applies the specified callback when event is fired.
			
		Parameters:
			- eventName :	(string) the name of the event to observe
			- callback :	(Function) the callback function to trigger if event is fired on target
	*/
	observe : function(eventName, callback){
		Event.observe(document, eventName, callback);
	},
	
	debug : function(){ // arguments expected
		if (window.console && window.console.log) {
			console.log.apply(console, arguments);
		}
	}
}

/**
 * @author Ryan Johnson <http://syntacticx.com/>
 * @copyright 2008 PersonalGrid Corporation <http://personalgrid.com/>
 * @package LivePipe UI
 * @license MIT
 * @url http://livepipe.net/controls/hotkey/
 * @attribution http://www.quirksmode.org/js/cookies.html
 */
var Cookie = {
	build: function() {
		return $A(arguments).compact().join("; ");
	},
	
	secondsFromNow: function(days) {
		var d = new Date();
		d.setTime(d.getTime() + (days*24*60*60*1000));
		return d.toGMTString();
	},
	
	set: function(name, value, days){
		var expiry = days ? 'expires=' + Cookie.secondsFromNow(days) : null;
		console.debug(Cookie.build(name + "=" + value, expiry, "path=/"));
		document.cookie = Cookie.build(name + "=" + value, expiry, "path=/");
	},
	
	get: function(name){
		var valueMatch = new RegExp(name + "=([^;]+)").exec(document.cookie);
		return valueMatch ? valueMatch[1] : null;
	},
	
	unset: function(name){
		Cookie.set(name,'',-1);
	}
};


// Email obfuscator script 2.1 by Tim Williams, University of Arizona
// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
// This code is freeware provided these four comment lines remain intact
// A wizard to generate this code is at http://www.jottings.com/obfuscator/
var EmailObfuscator = { 

	load : function(element){
		coded = "s7JPnhsE@wJsn7.OSJ"
		key = "nwHTDCeUFk5o8WJK96cRlYpaPd0jISuGNL14Ot7ZEs2higQzbxMAqyvBXVm3rf"
		shift = coded.length
		link=""
		for (i=0; i<coded.length; i++) {
			if (key.indexOf(coded.charAt(i))==-1) {
				ltr = coded.charAt(i)
				link += (ltr)
			}else{     
				ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length
				link += (key.charAt(ltr))
			}
		}
		$(element).update("<a href='mailto:"+link+"'>Pedro De Almeida</a> &copy; " + new Date().getFullYear());
	}
}

/* Shortcuts */
var _ = function(){ // arguments expected
	Utils.debug.apply(Utils, arguments)	
}
