In case you want to do all the Javascript hassle because you have unpredictable headers and don't know the exact position of main content it wold be enough to set the ccs to fixed and just calculate the position on start.
var headerOffset = $('#main-content').offset().top;
$('#sidebar').css('top', headerOffset);
like here:http://jsfiddle.net/4amdr/
Thats the only way I can imagine why you don't want to use a fixed top and leave js out.