var	preloadedImages

function drawLine( lineIndex, x1, y1, x2, y2 )
{
	objectHandle = document.getElementById( "line"+ lineIndex )
	if( !objectHandle )
	{
		e=document.getElementById( "linegraph" )
		e.innerHTML += "<img id='line"+ lineIndex +"' class='line' />"
		objectHandle = document.getElementById( "line"+ lineIndex )
	}

	updateLine( objectHandle, x1, y1, x2, y2 )
}

function updateLine( lineObjectHandle, Ax, Ay, Bx, By )
{
	var
		xMin		= Math.min( Ax, Bx ),
		yMin		= Math.min( Ay, By ),
		xMax		= Math.max( Ax, Bx ),
		yMax		= Math.max( Ay, By ),
		boxWidth	= Math.max( xMax-xMin, 1 ),
		boxHeight	= Math.max( yMax-yMin, 1 ),
		tmp			= Math.min( boxWidth, boxHeight, 256 ),
		lineIndex	= (Bx-Ax)*(By-Ay)<0?0:1

	while( tmp>>=1 )
		lineIndex+=2

	lineObjectHandle.src = preloadedImages[lineIndex].src
	with( lineObjectHandle.style )
	{
		width	= boxWidth	+"px"
		height	= boxHeight	+"px"
		left	= xMin		+"px"
		top		= yMin		+"px"
	}
}


onload = function()
{
	preloadedImages = document.images||document.getElementById('preload').getElementsByTagName('img')
	// setInterval( updateFrame, 100 )
}
