Well, just an idea on how to play with classes using jQuery:
http://jsfiddle.net/coma/G5CeM/
var body = $('body').on('mouseover', '[data-tip]', function(event) {
var self = $(this).removeClass('right');
var x = self.offset().left + self.width() / 2;
if (x < body.width() / 2) {
self.addClass('right');
}
});