jquery to calculate the relation of the reference and the selected