code: function() {
          
          var mapSize = this.map.getSize();
      
          //start with the top left corner of the popup, in px, 
          // relative to the viewport
          var origTL = this.map.getViewPortPxFromLayerPx( new OpenLayers.Pixel(
              parseInt(this.div.style.left),
              parseInt(this.div.style.top)
          ));
          var newTL = origTL.clone();
      
          //new left (compare to margins, using this.size to calculate right)
          if (origTL.x < this.map.paddingForPopups.left) {
              newTL.x = this.map.paddingForPopups.left;
          } else 
          if ( (origTL.x + this.size.w) > (mapSize.w - this.map.paddingForPopups.right)) {
              newTL.x = mapSize.w - this.map.paddingForPopups.right - this.size.w;
          }
          
          //new top (compare to margins, using this.size to calculate bottom)
          if (origTL.y < this.map.paddingForPopups.top) {
              newTL.y = this.map.paddingForPopups.top;
          } else 
          if ( (origTL.y + this.size.h) > (mapSize.h - this.map.paddingForPopups.bottom)) {
              newTL.y = mapSize.h - this.map.paddingForPopups.bottom - this.size.h;
          }
          
          var dx = origTL.x - newTL.x;
          var dy = origTL.y - newTL.y;
          
          this.map.pan(dx, dy);
      }
docs: Method: panIntoView
  Pans the map such that the popup is totaly viewable (if necessary)