Recentering divs on window resize gets me "Uncaught TypeErrors"
<p>I have got a modal window set-up on my page that works fine, but needs repositioning on window resize in order to stay centred. Unfortunately, I simply get the error:</p>

<blockquote>
  <p>Uncaught TypeError: Object # has no method 'outerHeight'</p>
</blockquote>

<p>Am I using "this" incorrectly?</p>

<pre><code>        $(window).resize(function() {
            //If mask is open, resize modal elements
            if ($('#modalMask').is(':visible')) {
                //Resize and position modal windows
                //Get window dimensions
                var mWinHeight = $(window).height();
                var mWinWidth = $(window).width();
                //Make sure all open modal windows are centred
                $('.modalWindow:visible').each(function (i) {
                    var $this = $(this);
                    $this.css('top', mWinHeight/2-(this.outerHeight()/2));
                    $this.css('left', mWinWidth/2-(this.outerWidth()/2));
                });
            }
        });
</code></pre>
