function opacity(id, fade_in, start_offset, ms)
{
	var speed = Math.round(ms / 100);
	var c = 0;

	if(fade_in == true)
	{
		for(i = 0; i <= 100; i++)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",((c * speed)+start_offset));
			c++;
		}
	}
	else
	{
		for(i = 100; i >= 0; i--)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",((c * speed)+start_offset));
			c++;
		}
	}
}

function trans_bgcolor(id, rgb_start, rgb_dest, start_offset, ms)
{
	var c = 0;
	var rd,gd,bd, rs, gs, bs, r, g, b;
	regex = /(\w\w)(\w\w)(\w\w)/;
	regex.exec(rgb_dest);
	rd = parseInt(RegExp.$1, 16);
	gd = parseInt(RegExp.$2, 16);
	bd = parseInt(RegExp.$3, 16);
	regex.exec(rgb_start);
	rs = parseInt(RegExp.$1, 16);
	r = rs;
	gs = parseInt(RegExp.$2, 16);
	g = gs;
	bs = parseInt(RegExp.$3, 16);
	b = bs;

	rdist = Math.abs(rs - rd);
	gdist = Math.abs(gs - gd);
	bdist = Math.abs(bs - bd);
	steps = rdist;
	if(gdist > steps)
		steps = gdist;
	if(bdist > steps)
		steps = bdist;
	var speed = Math.round(ms/steps)+1;
	for(i = 0; i < steps; i=i+2)
	{
		if(rs < rd)
			r += (rdist/steps)*2;
		else if(rs > rd)
			r -= (rdist/steps)*2;

		if(gs < gd)
			g += (gdist/steps)*2;
		else if(gs > gd)
			g -= (gdist/steps)*2;

		if(bs < bd)
			b += (bdist/steps)*2;
		else if(bs > bd)
			b -= (bdist/steps)*2;
		setTimeout("document.getElementById('"+id+"').style.backgroundColor = 'rgb("+Math.round(r)+","+Math.round(g)+","+Math.round(b)+")'", (i*speed)+start_offset);		
	}
	setTimeout("document.getElementById('"+id+"').style.backgroundColor = 'rgb("+Math.round(rd)+","+Math.round(gd)+","+Math.round(bd)+")'", (i*speed)+start_offset);		
}

function trans_txtcolor(id, rgb_start, rgb_dest, start_offset, ms)
{
	var a_item = document.getElementById(id).firstChild;
	if(a_item.nodeType == 1 && a_item.nodeName == "A")
	{
		id = a_item.id;
	}
	else
		alert(a_item);
	var c = 0;
	var rd,gd,bd, rs, gs, bs, r, g, b;
	regex = /(\w\w)(\w\w)(\w\w)/;
	regex.exec(rgb_dest);
	rd = parseInt(RegExp.$1, 16);
	gd = parseInt(RegExp.$2, 16);
	bd = parseInt(RegExp.$3, 16);
	regex.exec(rgb_start);
	rs = parseInt(RegExp.$1, 16);
	r = rs;
	gs = parseInt(RegExp.$2, 16);
	g = gs;
	bs = parseInt(RegExp.$3, 16);
	b = bs;

	rdist = Math.abs(rs - rd);
	gdist = Math.abs(gs - gd);
	bdist = Math.abs(bs - bd);
	steps = rdist;
	if(gdist > steps)
		steps = gdist;
	if(bdist > steps)
		steps = bdist;
	var speed = Math.round(ms/steps)+1;
	for(i = 0; i < steps; i=i+2)
	{
		if(rs < rd)
			r += (rdist/steps)*2;
		else if(rs > rd)
			r -= (rdist/steps)*2;

		if(gs < gd)
			g += (gdist/steps)*2;
		else if(gs > gd)
			g -= (gdist/steps)*2;

		if(bs < bd)
			b += (bdist/steps)*2;
		else if(bs > bd)
			b -= (bdist/steps)*2;
		setTimeout("document.getElementById('"+id+"').style.color = 'rgb("+Math.round(r)+","+Math.round(g)+","+Math.round(b)+")'", (i*speed)+start_offset);		
	}
	setTimeout("document.getElementById('"+id+"').style.color = 'rgb("+Math.round(rd)+","+Math.round(gd)+","+Math.round(bd)+")'", (i*speed)+start_offset);		
}

function move(id, dest_x, dest_y, start_offset, ms)
{
	var c = 0;
	var start_x = parseInt(document.getElementById(id).style.left);
	var start_y = parseInt(document.getElementById(id).style.top);
	
	var steps_x = Math.abs(start_x - dest_x);
	var steps_y = Math.abs(start_y - dest_y);
	var steps = steps_x;
	if(steps_y > steps_x)
		steps = steps_y;

	var speed = Math.round(ms/steps);
	var m,y,b,x, txt;
	if(dest_x != start_x)
		m = (dest_y - start_y)/(dest_x - start_x);
	else
		m = 9999;
	b = m*start_x;
	
	x = start_x;
	y = start_y;
	for(i = 0; i < steps; i++)
	{
		if(start_x < dest_x)
			x += steps_x/steps;
		else if(start_x > dest_x)
			x -= steps_x/steps;

		if(steps != steps_y)
			y = m*x+b;
		else if(start_y < dest_y)
			y++;
		else if(start_y > dest_y)
			y--;
		setTimeout("document.getElementById('"+id+"').style.left = '"+Math.round(x)+"px'", (c*speed)+start_offset);		
		setTimeout("document.getElementById('"+id+"').style.top = '"+Math.round(y)+"px'", (c*speed)+start_offset);
		c++;
	}
}

function fnugFade(id, pos, fade_in, fade_to, start_offset, ms)
{
	var c = 0;

	if(fade_in == true)
	{
		if(fade_to > 100 || fade_to < 1)
			fade_to = 100;
		var speed = Math.round(ms / fade_to);
		setTimeout("document.getElementById('"+id+"').style.display = 'block'", 2*speed+start_offset);
		setTimeout("document.getElementById('"+id+"').style.visibility = 'visible'", 2*speed+start_offset);

		for(i = 0; i <= fade_to; i++)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",((c * speed)+start_offset));
			c++;
		}
	}
	else
	{
		var fade_from = fade_to;
		if(fade_from > 100 || fade_from < 1)
			fade_from = 100;
		var speed = Math.round(ms / fade_from);
		for(i = fade_from; i >= 0; i--)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",((c * speed)+start_offset));
			c++;
		}
		setTimeout("document.getElementById('"+id+"').style.display = 'none'", c*speed+start_offset);
		setTimeout("document.getElementById('"+id+"').style.hidden = 'visible'", c*speed+start_offset);
	}
}

function fnugMoveWidth(id, newValue, ms)
{
	var c = 0;
	obj = document.getElementById(id);
	actual_width = parseInt(obj.style.width);
	var speed = Math.round(ms / Math,abs(newValue - actual_width));
	for(i = actual_width; i <= newValue; i++)
	{
		setTimeout("fnugProgress('"+id+"',"+i+")",((c * speed)));
		c++;
	}
}

function fnugProgress(id, val)
{
	obj = document.getElementById(id);
	actual_width = parseInt(obj.style.width);
	if(actual_width < val)
		obj.style.width = val.toString + "px";
}

function changeOpac(opacity, id)
{
	var obj = document.getElementById(id).style; 
	obj.opacity = (opacity / 100);
	obj.MozOpacity = (opacity / 100);
	obj.KhtmlOpacity = (opacity / 100);
	obj.filter = "alpha(opacity=" + opacity + ")";
}
