Moving a platform

Hi guys,

I am trying to move a platform up and down based on the positions of two other objects. I have the script below attached to my platform. My platform goes up smoothly but when it gets to its final position, it resets to the startMarker position instantly (instead of going down gradually). Any help would be appreciated.

Thanks!

var dir : int = 0; //0 = up; 1 = down


// Transforms to act as start and end markers for the journey.
var startMarker: Transform;
var endMarker: Transform;

// Movement speed in units/sec.
var speed = 0.2;

// Time when the movement started.
private var startTime: float;

// Total distance between the markers.
private var journeyLength: float;

var target : Transform;
var smooth = 5.0;

function Start() {
    // Keep a note of the time the movement started.
    startTime = Time.time;
    
    // Calculate the journey length.
    journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
}

// Follows the target position like with a spring
function Update () {         
             
    // Distance moved = time * speed.
    var distCovered = (Time.time - startTime) * speed;
    
    // Fraction of journey completed = current distance divided by total distance.
    var fracJourney = distCovered / journeyLength;
    
    if(dir == 0) // Going up
    {
        // Set our position as a fraction of the distance between the markers.
        transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney)
        
        //Check to see if platform reached destination. If so, reverse course
        if(transform.position == endMarker.position)
        {
        	dir = 1; //Change direction
        	startTime = Time.time; //Reset start time
        	//Debug.Log("Going down now...");
        }
    }
    
    if(dir == 1) // Going down
   	{
        
        // Set our position as a fraction of the distance between the markers.
        transform.position = Vector3.Lerp(endMarker.position, startMarker.position, fracJourney);
        
        //Check to see if platform reached destination. If so, reverse course
        if(transform.position == startMarker.position) 
        {
        	dir = 0;
        	startTime = Time.time; //Reset start time
        	//Debug.Log("Going up now...");
        }
    }
    //Debug.Log("fracJourney: " + fracJourney);
    
}

These vars needs to be updated before the journey downwards start

var fracJourney = distCovered / journeyLength;