To explain why your code doesn't work...
A function in Javascript has in scope all variables that were declared in containing functions or in that function. Using the var keyword sets a variable to the current scope. In your example, startOrigin is only in the scope of the first function. If you put it in the parent scope, all the functions in your example will have it in their scope:
var markers = $j('span.marker');
var startOrigin; // declare the variable in this scope
markers.each(function () { //function to store original marker positions
startOrigin = $j(this).css('margin-left'); // use the parent scope
});
$j("a.timeline-view").click(function () { //function to return markers to stored positions
markers.each(function () {
$j(this).animate({
marginLeft: startOrigin // use parent scope
})
});
});
Note, however, that this example is kind of broken anyway. You are looping through the whole set of markers, overwriting the startOrigin each time. You need to use data as Tom Tu said in his answer to set data for an individual DOM element.