if (typeof(Tfe) == 'undefined')
{
	Tfe = function() {};
}

/* Tfe.Utils */
Tfe.Utils = function() {};

/**
*	Method for retrieving the current style (CSS) of an HTML element.
*
*	Parameters:
*	- oElm:			The element which style should be retrieved.
*	- strCssRule:	The CSS style rule which value should be retrieved.
*/
Tfe.Utils.getCurrentStyle = function(oElm, strCssRule)
{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle) // Mozilla
	{
		var computedStyle = document.defaultView.getComputedStyle(oElm, '');
		if (computedStyle != null)
		{
			strValue = computedStyle.getPropertyValue(strCssRule);
		}
		else
		{
			// Safari 2 bug: If the current display style of the element is none, than the element is removed from the DOM.
			if (strCssRule == 'display')
			{
				return 'none';
			}
			else
			{
				return '';
			}
		}
	}
	else if(oElm.currentStyle) // Internet Explorer
	{
		strCssRule = strCssRule.replace(/-\w/g, 
			function (strMatch)
			{
				return strMatch.substr(1).toUpperCase();
			}
		);
		strValue = oElm.currentStyle[strCssRule];
		if (strValue == 'auto' && strCssRule == 'width')
		{
			strValue = oElm.clientWidth + 'px';
		}
		if (strValue == 'auto' && strCssRule == 'height')
		{
			strValue = oElm.clientHeight + 'px';
		}
	}
	return strValue;
}

/**
*	Method for retrieving the hexadecimal color code (HTML color) for a color returned from the browser.
*	If the supplied color contains a #, it is stripped.
*
*	Parameters:
*	- sBrowserColor:	The color code returned by the browser.
*/
Tfe.Utils.getHexColor = function (sBrowserColor)
{
	var htmlColor = 'ffffff';
	// Check if the color is a RGB code
	if (sBrowserColor.indexOf('rgb') == 0)
	{
		var aRGB = sBrowserColor.substring(sBrowserColor.indexOf('(') + 1, sBrowserColor.indexOf(')')).split(',');
		// Normal color (Red, Green, Blue)
		if (aRGB.length == 3)
		{
			htmlColor = this.decimalToHex(parseInt(aRGB[0],10)) + this.decimalToHex(parseInt(aRGB[1],10)) + this.decimalToHex(parseInt(aRGB[2],10));
		}
		// Safari transparent color (Red, Green, Blue, Alpha)
		if (aRGB.length == 4)
		{
			if (parseInt(aRGB[3],10) == 0) // Transparent
			{
				htmlColor = 'transparent';
			}
			else
			{
				htmlColor = this.decimalToHex(parseInt(aRGB[0],10)) + this.decimalToHex(parseInt(aRGB[1],10)) + this.decimalToHex(parseInt(aRGB[2],10));
			}
		}
	}
	else
	{
		// Check if the color contains a #
		if (sBrowserColor.indexOf('#') == 0)
		{
			htmlColor = sBrowserColor.substr(1);
		}
		else
		{
			htmlColor = sBrowserColor;
		}
	}
	return htmlColor.toLowerCase();
}

/**
*	Method to convert a decimal to it's hexadecimal equivalent.
*
*	Parameters:
*	- decimal:	The decimal value to be converted.
*/
Tfe.Utils.decimalToHex = function(decimal)
{
	var hex = decimal.toString(16);
	if (hex.length == 1)
	{
		hex = '0' + hex;
	}
	return hex;
}

/**
*	Method to add an event to a DOM object.
*
*	Parameters:
*	- elementObject:	The DOM object where the event should be added to.
*	- eventName:		The name of the event.
*	- functionObject:	The function which is called if the added event is triggered.
*/
Tfe.Utils.addEvent = function(elementObject, eventName, functionObject)
{
	if(document.attachEvent) // IE
	{ 
		elementObject.attachEvent("on" + eventName, function() { functionObject(elementObject) });
	}
	else if(document.addEventListener)  // Everything else
	{
		elementObject.addEventListener(eventName, function(evt) { functionObject(elementObject, evt) }, true);
	} 
}

