A solution was to separate the code. One for when the content height is lower than the window height and one when it's higher.
It's not perfect but it seems to work.
var container = jQuery('.container');
var object = jQuery('.object', container);
var containerHeight, containerOffsetTop,
objectHeight, objectNegativeMargin, objectOffsetTop,
heightPercent, objectMargin, mouseY;
object.mousemove(function(e){
containerHeight = container.height();
containerOffsetTop = container.offset().top;
objectHeight = object.height();
objectNegativeMargin = (objectHeight/2);
objectOffsetTop = object.offset().top;
if(objectHeight > containerHeight) {
heightPercent = (e.pageY - containerOffsetTop) / containerHeight;
objectMargin = -(heightPercent * (objectHeight-containerHeight));
} else {
mouseY = e.pageY - objectNegativeMargin;
objectMargin = (objectOffsetTop - mouseY)/2;
}
object.css({ marginTop : objectMargin });
});