/**
 * Javascript general GUI functions
 *
 * General GUI Javascript functions. (Fading, moving things around
 * with nice effects, etc.)
 *
 * @author	Philip Withnall <drbob@tecnocode.co.uk>
 * @copyright	Philip Withnall 2006
 * @package	General
 * @subpackage	Javascript
 * @version	1.1.1
 * @license	http://tecnocode.co.uk/links/sourcecode-license.html
 * @filesource
 */

/*
 * Fade element
 *
 * Fade an element in or out.
 *
 * @param	string		Element ID
 * @param	integer		Opacity to add/subtract
 * @param	integer		Time between opacity chages
 * @param	boolean		Increasing or decreasing opacity?
*/
function fade_object(fade_element_id,add_opacity,frequency,increasing_opacity)
{
	//Recommended values:
	// - add_opacity: 10
	// - frequency: 20
	var fade_element=document.getElementById(fade_element_id);

	if(fade_element)
	{
		if(fade_element.style.opacity=="")
		{
			fade_element.style.opacity=1;
		}
		else
		{
			fade_element.style.opacity=parseFloat(fade_element.style.opacity);
		}
	
		if(increasing_opacity)
		{
			var new_opacity=parseFloat(parseFloat(fade_element.style.opacity)+parseFloat(add_opacity));
		}
		else
		{
			var new_opacity=fade_element.style.opacity-add_opacity;
		}
	
		fade_element.style.opacity=new_opacity;
		if(((!increasing_opacity) && (new_opacity>0)) || ((increasing_opacity) && (new_opacity<1)))
		{
			setTimeout("fade_object('"+fade_element_id+"',"+add_opacity+","+frequency+","+increasing_opacity+")",frequency);
		}
	}
}

/*
 * Find X-position
 *
 * Find the X-position of the specified element.
 *
 * @param	object		Element
 * @return	integer		X-position
*/
function findPosX(obj)
{
	var curleft=0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curleft+=obj.offsetLeft
			obj=obj.offsetParent;
		}
	}
	else if(obj.x) curleft+=obj.x;
	return curleft;
}

/*
 * Find Y-position
 *
 * Find the Y-position of the specified element.
 *
 * @param	object		Element
 * @return	integer		Y-position
*/
function findPosY(obj)
{
	var curtop=0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curtop+=obj.offsetTop
			obj=obj.offsetParent;
		}
	}
	else if(obj.y) curtop+=obj.y;
	return curtop;
}
