### Eclipse Workspace Patch 1.0
#P hover_preview
Index: hover_preview.js
===================================================================
RCS file: /cvs/drupal/contributions/modules/hover_preview/hover_preview.js,v
retrieving revision 1.1
diff -u -r1.1 hover_preview.js
--- hover_preview.js	12 Feb 2010 00:25:08 -0000	1.1
+++ hover_preview.js	19 Jul 2010 15:32:28 -0000
@@ -11,31 +11,55 @@
 Drupal.behaviors.HoverPreview = function (context) {
   /* CONFIG */
     
-    xOffset = 10;
-    yOffset = 30;
+    yOffset = 10;
+    xOffset = 30;
+    docHeight = $(document).height(); //get here because document height could change during DOM manipulation 
     
     // these 2 variable determine popup's distance from the cursor
     // you might want to adjust to get the right result
     
   /* END CONFIG */
   $("img.hover-preview").hover(function(e){
+
     this.t = this.title;
     this.title = "";  
     var c = (this.t != "") ? "<br/>" + this.t : "";
-    var preview_link = $('#' + this.id + '-url')[0];
-    $("body").append("<p id='hover-preview'><img src='"+ preview_link.href +"' alt='Loading Image Preview' />"+ c +"</p>");                
+    var preview_link = $('#' + this.id + '-url')[0]; //why [0] ?
+    
+    img_width = $(preview_link).width();
+    img_height = $(preview_link).height();
+    
+    //Output of the preview element
+    $("body").append("<p id='hover-preview'><img src='"+ preview_link.src +"' alt='Loading Image Preview' />"+ c +"</p>");
     $("#hover-preview")
-      .css("top",(e.pageY - xOffset) + "px")
-      .css("left",(e.pageX + yOffset) + "px")
-      .fadeIn("fast");            
+      .css("top",(e.pageY - yOffset) + "px")
+      .css("left",(e.pageX + xOffset) + "px")
+      .fadeIn("fast");
     },
+    
   function(){
     this.title = this.t;  
     $("#hover-preview").remove();
-    }); 
+    });   
+
+  
+  //keep track of mouse movement in an image and move preview element
   $("img.hover-preview").mousemove(function(e){
+  
+  var elementHeight = $("p#hover-preview").outerHeight(true);
+  var winHeight = $(window).height();
+  var scrolledPixel = $(window).scrollTop();
+
+  if( ((winHeight - e.pageY + yOffset + scrolledPixel) <= elementHeight) ) {
+    var yPosition = winHeight - elementHeight + scrolledPixel;
+    $("#hover-preview")      
+        .css("top",(yPosition - yOffset) + "px")
+        .css("left",(e.pageX + xOffset) + "px");
+  } 
+   else {
     $("#hover-preview")
-      .css("top",(e.pageY - xOffset) + "px")
-      .css("left",(e.pageX + yOffset) + "px");
-  });     
+      .css("top",(e.pageY - yOffset) + "px")
+      .css("left",(e.pageX + xOffset) + "px");
+   }
+  });  
 };
