//$("a.image").each(function(){
//    id = $(this).parent().parent().attr("id");
//    if ($("#image_" + this.title).length == 0) {
//        $("#" + id + " .description").append("<div id='image_" + id + "'></div>");
//    }
//    
//    $("#image_" + id).html($("#image_" + id).html() + "<a href='" + this.href + "' target='_blank'><img src='" + this.href + "' width='50' class='image_preview' /></a>");
//});

$("a.image").hover(function(kmouse){
	if (!this.href) return;
    if (!$("#image_preview_over").length) $("body").append("<div id='image_preview_over'><img src='" + this.href + "' width='400' /></div>");
    tooltip = $("#image_preview_over");
    
    border_top = $(window).scrollTop();   
    border_right = $(window).width();  
    left_pos = top_pos = 0;  
    offset = 20;
    
    if(border_right - (offset *2) >= tooltip.width() + kmouse.pageX){  
        left_pos = kmouse.pageX + offset;  
    }else{  
        left_pos = border_right - tooltip.width() - offset;  
    }
               
    if(border_top + (offset *2) >= kmouse.pageY - tooltip.height()){  
        top_pos = border_top + offset;  
    }else{  
        top_pos = kmouse.pageY - tooltip.height() - offset;  
    }
    
    tooltip.css({left:left_pos, top:top_pos, position:'absolute'});
    tooltip.css({display:'block', visibility:'visible'});
}, function(){
    $("#image_preview_over").remove();
});
