find closest waypoint out of an array?

im working on ai for a hovercar game and all is working well exept i need it to find the closest waypoint so it never goes backwards becase at the moment it turns around and goes back to the last waypoint if it dident get within 10m of it? any idears on how to do this? hear is my current script

var waypoints : Transform[];
var speed = 0;
var upforce = 0;
var upforceidle = 0;

private var curwp : int;

function Start()
{
curwp = 0;
}


function Update () 
{
var hit : RaycastHit;

if (Vector3.Distance(waypoints[curwp].position, transform.position)< 10)
{
curwp ++;
}
transform.LookAt(waypoints[curwp]);
rigidbody.AddRelativeForce (Vector3.forward * speed);

if (Physics.Raycast (transform.position, -Vector3.up, hit)) 
{
if (hit.distance < 1)
{
rigidbody.AddForce (Vector3.up * upforce);
}
else
{
rigidbody.AddForce (Vector3.up * upforceidle);
}
}
}

bump anyone?

I did my waypoint a little different. I have the system just go from waypoint[0] to waypoint[9] (assuming you have 9 waypoints) then, I manually place them in order. I find this works better, because if you have a skinny course (where two waypoints are close, but not in the same order) the car may try to cheat