function _js_swapImage(id,i) 
{
	var obj;
	if (obj = document.getElementById(id));
	{
		obj.src = i;
	}
}

function _js_fadeInDelayPartial(id, millisec, delay, maxOpacity)
{
	_js_changeVisibility(true, id);
	setTimeout("_js_opacity('" + id + "',0," + maxOpacity + "," + millisec + ")", delay);
}

function _js_fadeIn(id, millisec)
{
	_js_changeVisibility(true, id);
	_js_opacity(id, 0, 100, millisec);
}

//change the opacity for different browsers
function _js_changeOpac(opacity, id) 
{
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
} 

function _js_opacity(id, opacStart, opacEnd, millisec) 
{
	var obj;
	
	if (!(obj = document.getElementById(id)))
	{
		return;
	}
	
	var style = obj.style;
	var curOpacity = style.opacity;
	
	//DEBUG
	if (false)
	{
		style.opacity = opacEnd;
		return;
	}
	
	if (curOpacity == opacEnd / 100.0)
	{
		return;
	}
	
	//speed for each frame
	var speed = Math.round(millisec / 100.0);
	var timer = 0;
	
	//determine the direction for the blending, if start and end are the same nothing happens
	if (opacStart > opacEnd) 
	{
		for (i=opacStart; i>=opacEnd; i--) 
		{
			setTimeout("_js_changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} 
	else if (opacStart < opacEnd) 
	{
		for (i=opacStart; i <= opacEnd; i++)
		{
			setTimeout("_js_changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function _js_posToPixel(s)
{
	return (parseInt(s.substring(0, s.length - 2)));
}

function _js_pixelToPos(x)
{
	return (x + "px");
}

function _js_random(min,max)
{
	var delta = max - min + 1;
	if (delta > 0)
	{
		return (Math.floor(Math.random() * delta + 1));
	}
}

function _js_setBackgroundPicture(id,pic)
{
	var obj;
	if (obj = document.getElementById(id))
	{
		obj.style.background = "transparent url( " + pic + " )";
		obj.style.backgroundRepeat = "no-repeat";
	}
	return false;
}

function _js_changeVisibility(show,id)
{
	var obj;
	var state = show ? "visible" : "hidden";
	//var zindex = show ? 1 : -1;
	if (obj = document.getElementById(id))
	{
		obj.style.visibility = state;
		//obj.style.zIndex = Math.abs(obj.style.zIndex) * zindex;
	}
	return false;
}

