var name = "#Rfloating";
var y = null;
$(function(){


    // name exists
    if (document.getElementById(name.replace('#', ''))) {
        y = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")))
        function scrollit() {
            offset = y + $(document).scrollTop();
            gap = (offset + $(name).height()) - ($(window).height() + $(document).scrollTop());
            // hit bottom
            if (gap > 0) {
                offset -= gap;
            }
            // hit top (original y offset)
            if (offset < y) {
                offset = y;
            }
            offset += "px";
            $(name).animate({
                top:offset
            },{
                duration:500,
                queue:false
            });
        }
        $(window).scroll(scrollit);
        scrollit();
    }
});
