/*
 *	Progress Control
 *	By Choeng junhwan (AccuZone Inc.)
 *
 *	2002-09-04
 *	
 *	version 0.1
 *
 */

document.write('<link rel="STYLESHEET" type="text/css" href="Progress.css">')


// constructor
function Progress(unWidth, unHeight, hLayer)
{
	// member variables
	var			m_unCurPos;
	var			m_unBeforePos;

	var			m_hView;
	
	var			m_hCell;

	var			m_unCelCount;

	var			m_hLayer;

	// initialize member variables
	this.m_hView				= document.createElement("DIV");
	this.m_hView.style.position	= 'relative';

	this.m_unCelCount	= 20;
	this.m_unCurPos		= 0;
	this.m_unBeforePos	= 0;
	this.m_hCell		= new Array(this.m_unCelCount);

	this.m_hLayer		= hLayer;

	// member methods
	this.Create			= Progress_Create;
	this.SetCurPos		= Progress_SetCurPos;
	this.GetCurPos		= Progress_GetCurPos;

	// create progress
	this.Create(unWidth, unHeight);
}


function Progress_Create(unWidth, unHeight)
{
	var			ProgTable;
	var			TableHead;
	var			TableBody;
	var			TableRow;
	var			TableCell;
	var			i;

	ProgTable		= document.createElement("TABLE");
	TableHead		= document.createElement("THEAD");
	TableBody		= document.createElement("TBODY");
	TableRow		= document.createElement("TR");

	ProgTable.appendChild( TableHead );
	ProgTable.appendChild( TableBody );

	ProgTable.cellPadding		= 2;
	ProgTable.cellSpacing		= 1;
	ProgTable.border			= 0;
	ProgTable.width				= unWidth;
	ProgTable.className			= "Progress";

	for ( i=0; i<this.m_unCelCount; i++)
	{
		TableCell			= document.createElement("TD");	
		TableCell.height	= unHeight;
		TableCell.width		= "5%";
		TableCell.className	= "Progress_BackgroundCell";
		TableRow.appendChild( TableCell );

		this.m_hCell[i]			= TableCell;
	}

	TableBody.appendChild( TableRow );

    this.m_hView.appendChild( ProgTable );

	if ( this.m_hLayer == null)
		document.body.appendChild(this.m_hView);
	else
		this.m_hLayer.appendChild(this.m_hView);

}

function Progress_SetCurPos(iPos)
{
	var			iLevel;
	var			i;
	
	if (iPos < 0)
		iPos		= 0;
	
	if (iPos > 100)
		iPos		= 100;

	if (this.m_unBeforePos >= 100 && iPos >= 100)
		return;

	this.m_unBeforePos		= this.m_unCurPos;
	this.m_unCurPos			= iPos;

	iLevel		= parseInt( iPos / 100 * this.m_unCelCount );

	if (iPos >= this.m_unBeforePos)
	{
		for ( i=0; i<iLevel; i++)
			this.m_hCell[i].className		= "Progress_ForegroundCell";
	}
	else
	{
		for ( i=0; i<m_unCelCount; i++)
		{
			if ( i < iLevel)
				this.m_hCell[i].className		= "Progress_ForegroundCell";
			else
				this.m_hCell[i].className		= "Progress_BackgroundCell";
		}
	}
}

function Progress_GetCurPos()
{
	return this.m_unCurPos;
}
