var tip;
$(document).ready(function () {
    $(".film-tile").mouseenter(function (event) {
        showTip($(this));
        event.cancelBubble = true;
    }).mouseout(function (event) {
        hideTip($(this), event);
    });
});

function showTip(elt) {

    $('.tooltip').hide();
    var s = elt.siblings()[0];
    $(s).css({ top: elt.position().top + 130, left: elt.position().left + 2 });
    $(s).show();
    tip = elt;
}

function hideTip(elt, event) {
    var inElt = isPosInElt(event.pageX, event.pageY, tip);
    if (!inElt) {
        var s = elt.siblings()[0];
        $(s).hide();
    }
}

function isPosInElt(x, y, elt) {
    var t = elt.offset().top;
    var b = elt.offset().top + elt.height() + 15;
    var l = elt.offset().left;
    var r = elt.offset().left + elt.width();
    if (y >= t && y <= b &&
			x >= l && x <= r) {
        return true;
    }
    return false;
}

