/* 
	Author: marele, Framfab
*/

/* 
	Utils Constructor
*/
function Utils()
{

}
/*
	Util func. Returns a reference to a node. Conditioned by support of document.getElementById.
	
	@param sId String : id of the node to get a reference to.
	@return Node
*/
Utils.prototype.getObj = function(sId)
{
	if(document.getElementById){
		var o = document.getElementById(sId);
		return o != null ? o : false;
	} else { return false; }
}
Utils.prototype.getAbsLeft = function (o){
	var iY = 0;
	while(o.offsetParent){
		iY += o.offsetLeft;
		o = o.offsetParent;
	}
	return iY;
}
Utils.prototype.getAbsTop = function (o){
	var iX = 0;
	while(o.offsetParent){
		//window.status += o.offsetParent.nodeName + "=" + o.offsetTop + " | ";
		iX += o.offsetTop;
		o = o.offsetParent;
	}
	return iX;
}
/*
	Util func: get the pixel padding of a node
	
	@param o Node : a node
	@param sDir String : Top || Right || Bottom || Left
	@return Number
*/
Utils.prototype.getPadding = function(o,sDir)
{
	if(window.getComputedStyle){ 	// gecko
		var iVal = window.getComputedStyle(o,null).getPropertyValue("padding-" + sDir.toLowerCase());
	} else if(o.currentStyle){	// ie
		var iVal = eval("o.currentStyle.padding" + sDir);
	} else { 				// fallback
		var iVal = eval("o.style.padding" + sDir);
	}
	return parseInt(iVal);
}
/*
	Util func: get the pixel margin of a node
	
	@param o Node : a node
	@param sDir String : Top || Right || Bottom || Left
	@return Number
*/
Utils.prototype.getMargin = function(o,sDir)
{
	if (window.getComputedStyle){ // gecko
		var iVal = window.getComputedStyle(o,null).getPropertyValue("margin-" + sDir.toLowerCase());
	} else if(o.currentStyle){	// ie
		var iVal = eval("o.currentStyle.margin" + sDir) != "" && eval("o.currentStyle.margin" + sDir) != "auto" ? eval("o.currentStyle.margin" + sDir) : 0;
	} else { 				// fallback
		var iVal = eval("o.style.margin" + sDir);
	}
	return parseInt(iVal);
}
/*
	Util func: 	Works like getElementsByTagName. Would have been nice to do a Object.prototype.getElementsByClassName instead, but then we have no IE-support.
			Looks for the passed string in the nodes class="" attribute, so the function will also return the element if it has multible selectors like: class="section info"
	
	@param oParent Node : the object in which you wish to find the elments
	@param sClassName String: the name of the class attribute you wish to find
	@return Array
*/
Utils.prototype.getElementsByClassName = function(oParent,sClassName)
{
	var aNodes = oParent.getElementsByTagName("*");
	var aReturn = [];
	for(var i=0; i<aNodes.length; i++){
		var sTmp = "#" + aNodes[i].className + "#";
		var sRegEx = "[ |#]" + sClassName + "[ |#]";
		if(sTmp.match(new RegExp(sRegEx))){ aReturn.push(aNodes[i]); }
	}
	return aReturn;
}
/*	
	For debug purposes.
	Lists all properties in an object.
*/
Utils.prototype.list = function(o)
{
	var s = "";
	for(p in o){
		s += p + "\n";
	}
	return s;
}
/*
	Util func: get the pixel length of the total number of <a>'s contained in an array of <li>'s
	
	@param aLis Array : an array of nodes
	@return Number
*/
Utils.prototype.getAllItemsLength = function(aLis)
{
	var iTotal = 0;
	for(var i=0; i<aLis.length; i++){
		iTotal += aLis[i].firstChild.offsetWidth + this.getMargin(aLis[i].firstChild,"Left");
	}
	return iTotal;
}
/*
	Description:
	
	@param
	@return
*/
Utils.prototype.doPopup = function(sHref,sId,sParams)
{
	var dummy = window.open(sHref,sId,sParams);
}
/*
	Description:
	
	@param
	@return
*/
Utils.prototype.popup = function(sHref,w,h)
{
	var sParams = "width=" + w + ", height=" + h + ", resizeable=no, menubar=no, scrollbars=yes, left=" + (screen.width - w) / 2 + ", top=" + (screen.height - h) / 2;
	this.doPopup(sHref,"FIH",sParams);
}
/*
	Description:
	
	@param
	@return
*/
Utils.prototype.spawnWindow = function(sHref)
{
	var dummy = window.open(sHref,"FIH");
}