/**
 * fLtools.css
 * @author Jonas Wilson Schnack
 * 
 * Tools I use a lot
 * 
 */

//--> document.getElementById(id) shorthand
var gebi = function( id ){ return document.getElementById( id ); };

//<---

//--> crossbrowser opacity setter
function set_opacity( opacity, element )
{
	var elementStyle = element.style;
	elementStyle.opacity = (opacity / 100);
	elementStyle.MozOpacity = (opacity / 100);
	elementStyle.KhtmlOpacity = (opacity / 100);
	elementStyle.filter = "alpha(opacity=" + opacity + ")";
}
//<---

//--> cross browser get computed style - (liftet from quirksmode.org and modified )
function getStyle( element, styleProp )
{
	if (element.currentStyle)
		var y = element.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(element,null).getPropertyValue(styleProp);
	return y;
}

//--> cross browser event listener adder and remover (liftet from quirksmode.org)
function addEventSimple(obj,evt,fn)
{
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
		
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn)
{
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
		
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

//<--

//--> An attemt to stop default action for events - works in IE and FF - (liftet from some site)
function stopEvent( event ) 
{ 
	//make sure we get the event - regardless of browser
	if (!event)
		var event = window.event;
	
	//e.cancelBubble is supported by IE - this will kill the bubbling process.
	event.cancelBubble = true;
	event.returnValue = false;

	//e.stopPropagation works only in Firefox.
	if ( event.stopPropagation ) 
	{
		event.stopPropagation();
		event.preventDefault();
	}
	return false;
}
//<---

//--> get absolute position of an element relative to window
function getAbsolutePosition( element )
{
	var element = element;
	var currentNode = element;
		
	var x = 0;
	var y = 0;
		
	while( currentNode.parentNode )
	{
		x += currentNode.offsetLeft;
		y += currentNode.offsetTop;
			
		currentNode = currentNode.parentNode;
	}
	return [x, y];
}
