Whenever something appears too repetitive, it normally is.. consider:
for (var i = 1; i <= 5; i++ ) { // i in [1,5]
var buttonNeight = $("#buttonbg" + i).height();
var textHeight = $("#tr" + i).height();
var ratio = 50-((textHeight-1)/buttonHeight/2*100);
$("#tr" + i).css({top : ratio+'%'});
}
Note that in this case there is no need to use an array because all the values are a direct function of i
.
Also, I haven't actually looked at what this is trying to accomplish, so there might be a good/accepted way to achieve the same goals in pure CSS without using JavaScript.