﻿/*  
JQuery-based Hover Boxes

Based on simple modifications from: http://www.kriesi.at/archives/create-simple-tooltips-with-css-and-jquery
    
*/

function enableHoverBoxes(target_items){
    $(target_items).each(function() {
        var hoverBox = "#" + $(this).attr("id") + "HoverBox";

        $(hoverBox).hide();

        $(this).mouseover(function() {
            $(hoverBox).fadeIn(300);
        }).mousemove(function(kmouse) {

            var existingWidth = $(hoverBox).width();
            var existingHeight = $(hoverBox).height();

            var border_top = $(window).scrollTop();
            var border_right = $(window).width();
            var left_pos;
            var top_pos;
            var offset = 15;
            if (border_right - (offset * 2) >= existingWidth + kmouse.pageX) {
                left_pos = kmouse.pageX + offset;
            } else {
                left_pos = border_right - existingWidth - offset;
            }

            if (border_top + (offset * 2) >= kmouse.pageY - existingHeight) {
                top_pos = border_top + offset;
            } else {
                top_pos = kmouse.pageY - existingHeight - offset;
            }

            $(hoverBox).css("left", left_pos).css("top", top_pos);
        }).mouseout(function() {
            $(hoverBox).css({ left: "-9999px" });
        });
    });
}