// Hash elements id
var Pool = {};
function $(sId){
	var oValue = Pool[sId];
	if(oValue) return oValue;
	else{
		oValue = document.getElementById(sId);
		Pool[sId] = oValue;
		return oValue;
	}
	return document.getElementById(sId);
}

//Event handling object
var Event = {
	attach: function(sEvent, fnFunction, oElement){
		if(!oElement || typeof oElement == "undefined") oElement = window;
		if(oElement.attachEvent){ //IE
			oElement['e'+sEvent+fnFunction] = fnFunction;
			oElement[sEvent+fnFunction] = function(){oElement['e'+sEvent+fnFunction]( window.event );}
			return oElement.attachEvent("on"+sEvent, oElement[sEvent+fnFunction]);
		}else oElement.addEventListener(sEvent, fnFunction, false); //FF
	}
};

//Simulate the _blank target for links
Event.attach("load", function(){
	var links = document.getElementsByTagName("a");
	for(i=0; i < links.length; i++){
		if(links[i].rel && links[i].rel.search("external") == 0){
			if(links[i].rel.search(":") != (-1)){
				aSplitted = links[i].rel.split(":");
				links[i].onclick = function(){
					window.open(this.href, "pop", "width="+aSplitted[1]+",height="+aSplitted[2]);
					return false;
				};
			}else{
				links[i].onclick = function(){
					window.open(this.href, "pop");
					return false;
				};
			}
		}
	}
});

// :hover effect for the menu
Event.attach("load", function(){
	if($("menu")){
		var aMenuItems = $("menu").getElementsByTagName("li");
		for(var iItems = aMenuItems.length-1, iPos; iItems>=0 && (iPos=aMenuItems[iItems]); --iItems){
			if(iPos.getElementsByTagName("ul")[0]){
				iPos.onmouseover = function(){this.getElementsByTagName("ul")[0].style.display = "block";};
				iPos.onmouseout = function(){this.getElementsByTagName("ul")[0].style.display = "none";};
			}
		}
	}
});

//Extend the String object: trim functionality
String.prototype.trim = function(){
	return this.replace(/^\s+|\s+$/g,"");
};

