
function CreateProcessBar( id, title, ply )

	local bar = { }

	bar.Title = title;
	bar.ThinkDelay = 1;
	bar.NextThink = 0;
	bar.Color = nil;
	bar.Linger = false;
	
	ply:GetTable().ProcessBars[id] = bar;

	ply:GetTable().ActiveProcessBar = id;

end
 
function SetColor( color, ply )

	ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Color = color;
	
end

function SetThink( think, ply )

	ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].ThinkFunc = think;

end

function SetThinkDelay( delay, ply )

	ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].ThinkDelay = delay;

end

function SetEstimatedTime( time, ply )

	ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].TimeDone = time;

end

function SetLinger( bool, ply )

	ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Linger = bool;

end

function EndProcessBar( ply )

	ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Time = CurTime();

	if( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Color ) then
	
		umsg.Start( "CCPB", ply );
			umsg.String( ply:GetTable().ActiveProcessBar );
			umsg.String( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Title );
			umsg.Float( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].TimeDone );
			umsg.Short( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Color.r );
			umsg.Short( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Color.g );
			umsg.Short( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Color.b );
			umsg.Short( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Color.a );
		umsg.End();
	
	else

		umsg.Start( "CPB", ply );
			umsg.String( ply:GetTable().ActiveProcessBar );
			umsg.String( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].Title );
			umsg.Float( ply:GetTable().ProcessBars[ply:GetTable().ActiveProcessBar].TimeDone );
		umsg.End();
		
	end

end

function GetPercentage( id, ply )

	local totaltime = ply:GetTable().ProcessBars[id].TimeDone;
	local timedone = CurTime() - ply:GetTable().ProcessBars[id].Time;

	local perc = ( timedone / totaltime ) * 100;

	return perc;

end

function DestroyProcessBar( id, ply )

	ply:GetTable().ProcessBars[id] = nil;

	umsg.Start( "RPB", ply );
		umsg.String( id );
	umsg.End();

end

