How can I determine the distance of an object to the right browser window border
$(window).width() - ($('#your-element').offset().left + $('#your-element').width());
That takes the width of your element adds it to the position of the element within the document and takes it away from the whole window size which should leave you with the right hand distance between element and window.