diff --git a/floating_block.js b/floating_block.js
index c4701d1..ef169fe 100755
--- a/floating_block.js
+++ b/floating_block.js
@@ -1,6 +1,6 @@
 
 /**
- * Provides the ability to fix a html block to a position on the page when the 
+ * Provides the ability to fix a html block to a position on the page when the
  * browser is scroled.
  *
  * This code is based on tableheader.js
@@ -28,16 +28,23 @@ Drupal.behaviors.blockFloat = {
     if (jQuery.isFunction(context.parent)) {
       context = context.parent();
       doResize = false;
-    }  
-    $(Drupal.settings.floating_block).each(function (i, selector) {
-      $(selector.toString() + ':not(.blockFloat-processed)', context).each(function (j, block) {
+    }
+    var settings = Drupal.settings.floating_block;
+
+    // Cycle through all of the blocks we want to float, tagging them if necessary
+    $(settings['selectors']).each(function (i, selector) {
+      var item = selector.split('|');
+      $(item[0].toString() + ':not(.blockFloat-processed)', context).each(function (j, block) {
         var blockInfo = [];
-        blockInfo.original_position = $(block).offset();
+        blockInfo.original_offset = $(block).offset();
+        blockInfo.original_position = $(block).position();
         blockInfo.original_css_position = $(block).css("position");
         blockInfo.original_identifier = 'blockFloat-' + floating_blocks.length;
         blockInfo.viewHeight = 0;
+        blockInfo.container = item[1];
+        blockInfo.minOffset = 0;
+        blockInfo.maxOffset = 0;
         floating_blocks.push(blockInfo);
-        // Initialzing block positioning.
         tracker(blockInfo);
         $(block).addClass('blockFloat-processed ' + blockInfo.original_identifier);
       });
@@ -48,27 +55,39 @@ Drupal.behaviors.blockFloat = {
       // Save positioning data.
       var viewHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
       var block = $('.' + e.original_identifier);
+      e.minOffset = e.original_offset.top;
+      if (e.container) {
+        var containerHeight = $(e.container).height();
+        e.minOffset = Math.round($(e.container).position().top);
+        e.maxOffset = Math.round(containerHeight + e.minOffset - e.blockHeight - 10);
+      }
+      else {
+        e.maxOffset = viewHeight;
+      }
+
       if (block.length > 0) {
         if (e.viewHeight != viewHeight) {
           if (e.reset) {
             //reset block so we can calculate new position
-            block.css({left: e.original_position.left + 'px', position: e.original_css_position, top: e.original_position.top + 'px'});
-            e.original_position = $(block).offset();
+            block.css({left: e.original_offset.left + 'px', position: e.original_css_position, top: e.original_offset.top + 'px'});
+            e.original_offset = $(block).offset();
             e.original_css_position = $(block).css("position");
           }
           e.viewHeight = viewHeight;
           e.docHeight = $(document).height();
-          e.vPosition = e.original_position.top;
-          e.hPosition = e.original_position.left;
+          e.vPosition = e.original_offset.top;
+          e.hPosition = e.original_offset.left;
           e.blockHeight = block.height();
         }
 
         // Track horizontal positioning relative to the viewport and set position.
         var current_position = block.offset();
         var hScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
-        var vOffset = (document.documentElement.scrollTop || document.body.scrollTop) - e.vPosition;
+        // The offset begins!
+        var scrolli = (document.documentElement.scrollTop || document.body.scrollTop) ;
 
-        if (vOffset > 0) {
+        // make sure we're scrolling within the right region
+        if (scrolli > e.minOffset && scrolli <= e.maxOffset ) { // && scrolli < e.maxOffset) {
           //Don't let the bottom of the block go beneath the document height
           var topPosition = 0;
           if ((current_position.top + e.blockHeight) > e.docHeight) {
@@ -77,7 +96,16 @@ Drupal.behaviors.blockFloat = {
           block.css({left: -hScroll + e.hPosition + 'px', position: 'fixed', top: topPosition + 'px'});
         }
         else {
-          block.css({left: e.original_position.left + 'px', position: e.original_css_position, top: e.original_position.top + 'px'});
+          // nearing the top
+          if (scrolli < e.minOffset) {
+            block.css({left: e.original_offset.left + 'px', position: e.original_css_position, top: e.original_offset.top + 'px'});
+            block.css({left: '0px', position: e.original_css_position, top: '0px'});
+          }
+          // nearing the bottom
+          else {
+            block.css({left: e.original_position.left + 'px', position: 'relative', top: (containerHeight - e.blockHeight) + 'px'});
+            block.css({left: '0px', position: 'relative', top: (containerHeight - e.blockHeight) + 'px'});
+          }
         }
       }
     }
@@ -114,10 +142,10 @@ Drupal.behaviors.blockFloat = {
         time = null;
       }, 250);
     };
-    
+  
     if (doResize) {
       $(window).resize(resize);
     }
   }
 };
-})(jQuery);
\ No newline at end of file
+})(jQuery);
diff --git a/floating_block.module b/floating_block.module
index 12deb53..622e5d1 100755
--- a/floating_block.module
+++ b/floating_block.module
@@ -11,7 +11,9 @@
 function floating_block_init() {
   $selectors = preg_split("/(\r\n|\n)/", variable_get('floating_block_to_apply', ''));
   if (count($selectors)) {
-    drupal_add_js(array('floating_block' => $selectors), array('type' => 'setting', 'scope' => JS_DEFAULT));
+    drupal_add_js(array('floating_block' => array(
+      'selectors' => $selectors,
+    )), array('type' => 'setting', 'scope' => JS_DEFAULT));
     $path = drupal_get_path('module', 'floating_block');
     drupal_add_js($path . '/floating_block.js');
   }
@@ -41,7 +43,7 @@ function floating_block_admin($form, &$form_state) {
     '#type' => 'textarea',
     '#title' => t('CSS Classes/Selectors to <em>Include</em>'),
     '#default_value' => variable_get('floating_block_to_apply', ''),
-    '#description' => t('CSS selectors including id or class where to apply the floating block to. For example use <code>#sidebar-left</code> for ID, <code>.sidebar-left</code> for classes, and/or <code>#floating-block .floating_block</code> for combination. One selector per line.'),
+    '#description' => t('CSS selectors of blocks you want to float followed by an optional container id, separated with a | symbol, one per line. For example use <code>#block-block-1</code> to float on the entire page or <code>#block-block-1|#main</code> to float Block 1 within a container in your theme called <code>#main</code>.'),
   );
   return system_settings_form($form);
 }
