//tooltips
function simple_tooltip(target_items,name){
    my_tooltip = $("<div id='tooltip_div' class='"+name+"' style='display: none;'></div>").appendTo('body');
    $(target_items).each(function(i){
    tooltip_timeout = false;
    $(this).removeAttr("title").mouseover(function(){
            if (tooltip_timeout!=false) {
                clearTimeout(tooltip_timeout);
            }
            var link = $(this).next().html();
            tooltip_timeout = setTimeout(
                function() {
                    var tooltip_img = link;
                    my_tooltip.html(tooltip_img);
                    my_tooltip.css({display:"none"}).fadeIn(400);
                }, 500
            );
        }).mousemove(function(kmouse){
            //console.log($(window).width()+' '+$(window).height());
            var win_width = $(window).width();
            var win_height = $(window).height();
            var win_width_delta = win_width-kmouse.clientX;
            var win_height_delta = win_height-kmouse.clientY;
            //console.log(win_width_delta);
            if (win_width_delta < 400 && win_height_delta < 300) {
                var position_array = {right:win_width-kmouse.pageX+15, bottom:win_height-kmouse.pageY+15, left: '', top: ''};
            } else if (win_width_delta < 400) {
                var position_array = {right:win_width-kmouse.pageX+15, top:kmouse.pageY+15, left: '', bottom: ''};
            } else if (win_height_delta < 300) {
                var position_array = {left:kmouse.pageX+15, bottom:win_height-kmouse.pageY+15, right: '', top: ''};
            } else {
                var position_array = {left:kmouse.pageX+15, top:kmouse.pageY+15, right:'', bottom: ''};
            }
            my_tooltip.css(position_array);
        }).mouseout(function(){
            if (tooltip_timeout!=false) {
                clearTimeout(tooltip_timeout);
            }
            my_tooltip.fadeOut(400);
        });
    });
}
