var cur_pos = 0; // current position of animation
var save_dist = 0; //saves distance handed over in the beginning
var direction = '';//used to hold directional variable
var running = 0;
on = 0;

function MoveObjX(theElemName,dist,stepSize,stepTime,endframe)
{
		var move_loc = 0; //hold current location of the move_container
		var new_pos = 0; // for new position
		var dir_test = 0; // directional test
		
	    theElem = document.getElementById(theElemName); // get the move_container
		
		if ( running == 0 )
		{ 
			dir_test = dist - cur_pos; // find which direction and actual distance to trave
			if ( dir_test > 0 ) direction = 'right';
			else if (dir_test < 0 ) 
			{
				direction = 'left';
				dir_test = -1 * dir_test;
			}
			dist = dir_test;
			running = 1;
		} 
		
		if ( direction == 'right' ) //moving container to the right, will need to negate the final number
		{ 
			current_location = parseInt(theElem.style.left); //find the current x position of container
			if (current_location < 0) current_location = current_location * -1; //if negative, make it positive again
			new_pos = dist * stepSize; //how far do we need to move based off of speed
			cur_pos = new_pos + current_location; // add on the new number to the current location
			dist = dist - new_pos; // subtracting the size off the current distance left to travel
		
			if (dist < endframe )
			{ 
				cur_pos = save_dist;
				running = 0;
				theElem.style.left = (-1*cur_pos) + "px";
			} 
			else
			{ 
				theElem.style.left = (-1*cur_pos) + "px";    
        		theCall = "MoveObjX('" + theElemName + "'," + dist + "," + stepSize + "," + stepTime + "," + endframe + ")";
				running = 1;
        		setTimeout(theCall,stepTime);
			} 
		} 
			else if (direction == 'left' ) // moving container to the left, no negation required.
		{ 
			current_location = parseInt(theElem.style.left); //find the current x position of container
			//alert("the Location, Cur_pos and Dist = " + current_location + ", " + cur_pos + ", " + dist);
			if (current_location < 0) current_location = current_location * -1; //if negative, make it positive again
			new_pos = dist * stepSize; //how far do we need to move based off of speed
			cur_pos = current_location - new_pos; // add on the new number to the current location
			dist = dist - new_pos; // subtracting the size off the current distance left to travel
		
			if (dist < 10 )
			{ 
				cur_pos = save_dist;
				running = 0;
				theElem.style.left = (-1*cur_pos) + "px";
			} 
			else
			{ 
				theElem.style.left = (-1*cur_pos) + "px";    
        		theCall = "MoveObjX('" + theElemName + "'," + dist + "," + stepSize + "," + stepTime + "," + endframe + ")";
				running = 1;
        		setTimeout(theCall,stepTime);
			} 
		} 
}
        
function moveimage(dist)
{
	save_dist = dist;
	running = 0;
	MoveObjX("move_container",dist,.35,1,2);
}