"this" not accessible in embedded function used for Effects
<p>Regarding the object below I am getting a " 'this' is undefined error".  This only occurs in the next() function block...as commented below, if it is placed in the Effects function block there is no error.</p>

<p>This is only test code...my goal is to pass the element in through the constructor.  This test code has it passed in from both the constructor and the function because I'm testing it.  Once it passes I will take out the function argument from fade().</p>

<p>Also the Object Usage, happens to be in another object, that is why you see "this" there as well.</p>

<p><strong>Object Usage:</strong></p>

<pre><code>var EffectsObject = new Effects( this.element );
EffectsObject.fade( this.element, 'down', 4000);
</code></pre>

<p><strong>Object Definition:</strong></p>

<pre><code>var Effects = function( element ) 
{
    this.element2 = element;
};

Effects.prototype.fade = function( element1, direction, max_time ) 
{
    Effects.elapsed = 0;
    this.element2 = foo;      // works here but not if I put it in next();
    function next() 
    {
        Effects.elapsed += 10;
        if ( direction === 'up' )
        {
            element2.style.opacity = Effects.elapsed / max_time; // fails here
        }
        else if ( direction === 'down' )
        {
            this.element2.style.opacity = ( max_time - Effects.elapsed ) / max_time;
        }
        if ( Effects.elapsed &lt;= max_time ) 
        {
            setTimeout( next, 10 );
        }
    }
    next();
    return true;
};
</code></pre>
