﻿/****************************************
*               RCDelegate
*****************************************/

/// <summary>
/// Richer Components - Delegate Class
/// </summary>
function RCDelegate() 
{
}

/// <summary>
/// Create and returns a new delegate function
/// </summary>
RCDelegate.Create = function( object, delegatedFunction ) 
{
    var array = null;
    var newDelegate = null;
    
    //Create the new array
    array = new Array();
    
    //Loop without taking in count the 'object' and 'delegatedFunction' parameters
	for(var i = 2; i < arguments.length; i++) 
	    array[i - 2] = arguments[i];
	    
	//Create the new delegate function
	newDelegate = function() 
                {
		            var delegateParameters = null;
		            
		            //Create the delegate parameters
		            delegateParameters = new Array().concat(arguments, array);
		            //Apply it to the delegated function
		            delegatedFunction.apply(object, delegateParameters);
	            };
	            
	return newDelegate;
} // Create

/****************************************
*               RCMotionType
*****************************************/

/// <summary>
/// Richer Components - Motion Type Enum
/// </summary>
var RCMotionType =
{
    ElasticOut : 0,
    BounceOut : 1,
    BackOut : 2
}

/****************************************
*               RCMotion
*****************************************/

/// <summary>
/// Richer Components - Motion Effect Class
/// </summary>
function RCMotion( objId )
{
    this.ObjectId = objId;
    this.StyleProperty = 'left';
    this.MotionType = RCMotionType.ElasticOut;
    this.StartPosition = 0;
    this.EndPosition = 0;
    this.Duration = 1;
    this.Measure = 'px';
    this._object = null;
    this._objectStyle = null;
    this._currentPosition = this.StartPosition;
    this._previousTime = 0;
    this._previousPosition = 0;
    this._currentTime = 0;
    this._listeners = new Array();
    this._isPlaying = false;
    this._startTime = 0;
    this._change = 0;
    this._looping = false;
    
    this.SetFinish( 100 );
    this.AddListener( this );
} // RCMotion

/// <summary>
/// Richer Components - Motion Effect Class Prototype
/// </summary>
RCMotion.prototype = 
{
    /// <summary>
    /// Executes the show command
    /// </summary>
    ExecuteShow : function()
    {
        var element = null;
        
        //Get the element
        element = $( this.ObjectId );
        
        //Update the style of the element first
        element.style.display = 'block';
		element.style.visibility = 'visible';
		
        this.Start();
    }, // ExecuteShow
    
    /// <summary>
    /// Executes the hide command
    /// </summary>
    ExecuteHide : function()
    {
        var start = this.StartPosition;
        var end = this.EndPosition;
        
        this.StartPosition = end;
        this.SetFinish( start );
        
        this.Start();
    }, // ExecuteHide
    
    /// <summary>
    /// Check for the motion object to exists
    /// </summary>
    CheckMotionObject : function()
    {
        this._object = $( this.ObjectId );
        this._objectStyle = this._object.style;
    }, // CheckMotionObject

    /// <summary>
    /// Set Time
    /// </summary>
    SetTime : function( time )
    {
        //Update previous time
	    this._previousTime = this._currentTime;
	    
	    if ( time > this.Duration ) 
	    {
		    if ( this._looping ) 
		    {
			    this.Rewind( time - this.Duration );
			    this.Update();
			    this.SendMessage('onMotionLooped',{target:this,type:'onMotionLooped'});
		    }
		    else
		    {
			    this._time = this._duration;
			    this.Update();
			    this.Stop();
			    this.SendMessage('onMotionFinished',{target:this,type:'onMotionFinished'});
		    }
	    } 
	    else if ( time < 0 ) 
	    {
		    this.Rewind();
		    this.Update();
	    }
	    else 
	    {
		    this._currentTime = time;
		    this.Update();
	    }
    }, //SetTime
    
    /// <summary>
    /// Rewind the motion
    /// </summary>
    Rewind : function( time )
    {
        this.Stop();
	    this._currentTime = (time == undefined) ? 0 : time;
	    this.FixTime();
	    this.Update();
    }, // Rewind
    
    /// <summary>
    /// Rewind the motion
    /// </summary>
    Stop : function()
    {
        this.StopEnterFrame();
	    this.SendMessage('onMotionStopped', {target: this,type: 'onMotionStopped'} );
    }, // Stop
    
    /// <summary>
    /// Send a message to the listeners
    /// </summary>
    SendMessage : function()
    {
        var array = null;
        
        array = new Array();
	    for(var i = 0; i < arguments.length; i++)
	        array.push( arguments[i] );

	    var event = array.shift();	    
	    for (var i = 0; i < this._listeners.length; i++)
	    {
		    if ( this._listeners[i][event] )
		        this._listeners[i][event].apply( this._listeners[i], array );
	    }
    }, // SendMessage
    
    /// <summary>
    /// Stop the Enter Frame process
    /// </summary>
    StopEnterFrame : function()
    {
        this._isPlaying = false;
    }, // StopEnterFrame
    
    /// <summary>
    /// Start the Enter Frame process
    /// </summary>
    StartEnterFrame : function()
    {
        this.StopEnterFrame();
	    this._isPlaying = true;
	    this.OnEnterFrame();
    }, // StartEnterFrame
    
    /// <summary>
    /// On Enter Frame
    /// </summary>
    OnEnterFrame : function()
    {
        if ( this._isPlaying ) 
        {
		    this.NextFrame();
		    //Set the time out for the next frame
		    window.setTimeout( RCDelegate.Create(this, this.OnEnterFrame), 0 );
	    }
    }, // OnEnterFrame
    
    /// <summary>
    /// Advance to the next frame
    /// </summary>
    NextFrame : function()
    {
        this.SetTime( (this.GetTimer() - this._startTime) / 1000 );
    }, // NextFrame
    
    /// <summary>
    /// Advance to the next frame
    /// </summary>
    GetTimer : function()
    {
        return new Date().getTime() - this._currentTime;
    }, // GetTimer
    
    /// <summary>
    /// Update the current position
    /// </summary>
    Update : function()
    {
        this.SetPosition( this.GetPosition( this._currentTime ) );
    }, // Update
    
    /// <summary>
    /// Set a new position for the motion
    /// </summary>
    SetPosition : function( newPosition )
    {
        var measure = '';
        
        //Get the measure
        if ( this.Measure )
            measure = this.Measure;
            
        this.CheckMotionObject();
        
        this._previousPosition = this._currentPosition;
	    this._objectStyle[this.StyleProperty] = Math.round(newPosition) + measure;
	    this._currentPosition = newPosition;
	    
	    this.SendMessage('onMotionChanged',{target:this,type:'onMotionChanged'});
    }, // SetPosition
    
    /// <summary>
    /// Fix the time
    /// </summary>
    FixTime : function()
    {
        this._startTime = this.GetTimer() - this._currentTime * 1000;
    }, // FixTime
    
    /// <summary>
    /// Set the finish position
    /// </summary>
    SetFinish : function( finalPosition )
    {
        this.EndPosition = finalPosition;
        this._change = finalPosition - this.StartPosition;
    }, // SetFinish
    
    /// <summary>
    /// Get the finish position
    /// </summary>
    GetFinish : function()
    {
        return this._change + this.StartPosition;
    }, // GetFinish
    
    /// <summary>
    /// Start the motion
    /// </summary>
    Start : function()
    {
        this.Rewind();
	    this.StartEnterFrame();
	    this.SendMessage('onMotionStarted',{target:this,type:'onMotionStarted'});
    }, // Start
    
    /// <summary>
    /// Add a new listener to the motion
    /// </summary>
    AddListener : function( listener )
    {
        this.RemoveListener( listener );
	    return this._listeners.push( listener );
    }, // AddListener
    
    /// <summary>
    /// Remove the given listener from the motion
    /// </summary>
    RemoveListener : function( listener )
    {
        var removed = false;
	    var i = this._listeners.length;
	    
	    while ( i-- && ! removed ) 
	    {
		    if ( this._listeners[i] == listener ) 
		    {
			    this._listeners.splice(i, 1);
			    removed = true;
		    }
	    }
	    
	    return removed;
    }, // RemoveListener
    
    /// <summary>
    /// Resume the motion
    /// </summary>
    Resume : function()
    {
        this.FixTime();
	    this.StartEnterFrame();
	    this.SendMessage('onMotionResumed',{target:this,type:'onMotionResumed'});
    }, // Resume
    
    /// <summary>
    /// Get position of the motion
    /// </summary>
    GetPosition : function( time )
    {
        var value = 0;
        
        if (time == undefined) 
            time = this._currentTime;
            
        switch ( this.MotionType )
        {
            case RCMotionType.ElasticOut:
                value = this.ElasticOutF(time, this.StartPosition, this._change, this.Duration);
                break;
                
            case RCMotionType.BounceOut:
                value = this.BounceOutF(time, this.StartPosition, this._change, this.Duration);
                break;
                
            case RCMotionType.BackOut:
                value = this.BackOutF(time, this.StartPosition, this._change, this.Duration);
                break;
        }
        
        return value;
    }, // GetPosition
    
    /// <summary>
    /// Elastic Out Formula
    /// </summary>
    ElasticOutF : function ( time, startPosition, change, duration )
    {
        var value = 0;
        var speed = 0;
        var a = null;
        var p = null;
        
		if ( time == 0 ) 
		{
		    value = startPosition;  
		}
		else if ( ( time /= duration ) == 1 ) 
	    {
		    value = startPosition + change;  
		}
		else
		{
		    if ( ! p ) 
		    {
		        p = duration * 0.3;
		    }
    		
		    if ( ! a || a < Math.abs(change) ) 
		    { 
		        a = change; 
		        speed = p / 4;
		    }
		    else 
		    {
		        speed = p / ( 2 * Math.PI ) * Math.asin ( change / a );
		    }
    		
		    value = ( a * Math.pow( 2, -10 * time ) * Math.sin( ( time * duration - speed ) * ( 2 * Math.PI ) / p ) + change + startPosition);
		}
		
		return value;
	}, // ElasticOutF
	
	/// <summary>
    /// Bounce Out Formula
    /// </summary>
	BounceOutF : function ( time, startPosition, change, duration )
	{
	    var value = 0;
	    
	    if ( ( time /= duration ) < ( 1 / 2.75 ) ) 
	    {
		    value = change * ( 7.5625 * time * time ) + startPosition;
	    } 
	    else if ( time < ( 2 / 2.75 ) ) 
	    {
		    value = change * ( 7.5625 * ( time -= ( 1.5 / 2.75 ) ) * time + 0.75 ) + startPosition;
	    } 
	    else if ( time < ( 2.5 / 2.75 ) ) 
	    {
		    value = change * ( 7.5625 * ( time -= ( 2.25 / 2.75 ) ) * time + 0.9375 ) + startPosition;
	    } 
	    else 
	    {
		    value = change * ( 7.5625 * ( time -= ( 2.625 / 2.75 ) ) * time + 0.984375 ) + startPosition;
	    }
	    
	    return value;
    }, // BounceOutF
    
    /// <summary>
    /// Back Out Formula
    /// </summary>
    BackOutF : function ( time, startPosition, change, duration ) 
    {
        var a = null;
        var p = null;
        var speed = 1.70158;
	    
	    return change * ( ( time = time / duration - 1 ) * time * ( ( speed + 1 ) * time + speed ) + 1 ) + startPosition;
    } // BackOutF
} // RCMotion.prototype

/****************************************
*               RCSlide
*****************************************/

/// <summary>
/// Richer Components - Slide Effect Class
/// </summary>
function RCSlide( objId, speed )
{
    this._objId = objId;
    this._speed = speed; // Higher is faster
    this._currentSpeed = this._speed;
    this._timeOut = 10; // Lower is faster
    this._executing = false;
    this._originalValue = null;
    this._listeners = new Array();
    this.Vertically = true;
    
    this.AddListener( this );
} // RCSlide

/// <summary>
/// Richer Components - Slide Effect Class Prototype
/// </summary>
RCSlide.prototype = 
{
    /// <summary>
    /// Executes the show command
    /// </summary>
    ExecuteShow : function()
    {
        this.Show();
    }, // ExecuteShow
    
    /// <summary>
    /// Executes the hide command
    /// </summary>
    ExecuteHide : function()
    {
        this.Hide();
    }, // ExecuteHide
    
    /// <summary>
    /// Add a new listener
    /// </summary>
    AddListener : function( listener )
    {
        this.RemoveListener( listener );
	    return this._listeners.push( listener );
    }, // AddListener
    
    /// <summary>
    /// Remove the given listener
    /// </summary>
    RemoveListener : function( listener )
    {
        var removed = false;
	    var i = this._listeners.length;
	    
	    while ( i-- && ! removed ) 
	    {
		    if ( this._listeners[i] == listener ) 
		    {
			    this._listeners.splice(i, 1);
			    removed = true;
		    }
	    }
	    
	    return removed;
    }, // RemoveListener
    
    /// <summary>
    /// Send a message to the listeners
    /// </summary>
    SendMessage : function()
    {
        var array = null;
        
        array = new Array();
	    for(var i = 0; i < arguments.length; i++)
	        array.push( arguments[i] );

	    var event = array.shift();	    
	    for (var i = 0; i < this._listeners.length; i++)
	    {
		    if ( this._listeners[i][event] )
		        this._listeners[i][event].apply( this._listeners[i], array );
	    }
    }, // SendMessage
    
    /// <summary>
    /// Lock this instance for executing process
    /// returns true if the lock was successful and false if not
    /// </summary>
    _Lock : function()
    {   
        var locked = false;
        
        //Check for another execution
        if ( ! this._executing )
        {
            //Lock for executing
            this._executing = true;
            locked = true;
        }
        
        return locked;
    }, // _Lock
    
    /// <summary>
    /// Unlock this instance for future process
    /// </summary>
    _Unlock : function()
    {
        this._executing = false;
    }, // _Unlock

    /// <summary>
    /// Shows the slide
    /// </summary>
    Show : function()
    {
        var element = null;
        
        //Try to lock first this process
        if ( this._Lock() )
        {
            this.SendMessage('onSlideStart',{target:this,type:'onSlideStart'});
        
            //Get the element
            element = $( this._objId );
            //Update speed
            this._currentSpeed = this._speed;
    	    
            //save the height state
            if ( this._originalValue == null )
            {
                if ( this.Vertically )
                    this._originalValue = GetHeight( element );
                else
                    this._originalValue = GetWidth( element );
            }
            
            //Check if is already visible to the user
	        if ( this._GetElementCurrentValue() >= this._originalValue )
	        {
	            //Hide so we can start the show process again
	            if ( this.Vertically )
                    element.style.height = '0px';
                else
                    element.style.width = '0px';
	            
	            element.style.display = 'none';
	        }
            
            this._DoSlide();
            
            //Unlock the process
            this._Unlock();
        }
    }, // Show
    
    /// <summary>
    /// Hide the slide
    /// </summary>
    Hide : function()
    {
        var element = null;
        
        //Try to lock first this process
        if ( this._Lock() )
        {
            //Get the element
            element = $( this._objId );
            //Update speed
            this._currentSpeed = this._speed * -1;
            
            //save the height state
            if ( this._originalValue == null )
            {
                if ( this.Vertically )
                    this._originalValue = GetHeight( element );
                else
                    this._originalValue = GetWidth( element );
            }
            
            //Check if is already visible to the user
	        if ( this._GetElementCurrentValue() <= 1 )
	        {
	            //Show so we can start the hide process again
	            if ( this.Vertically )
                    element.style.height = this._originalValue + 'px';
                else
                    element.style.width = this._originalValue + 'px';
                    
	            element.style.display = 'block';
		        element.style.visibility = 'visible';
	        }
            
            this._DoSlide();
            
            //Unlock the process
            this._Unlock();
        }
    }, // Hide
    
    /// <summary>
    /// Returns the element current height
    /// </summary>
    _GetElementCurrentValue : function ()
    {
        var value = 0;
        var element = null;
        
        //Get the element
        element = $( this._objId );
        
        if ( this.Vertically )
            value = GetHeight( element );
        else
            value = GetWidth( element );
	        
	    return value;
    }, // _GetElementCurrentValue
    
    /// <summary>
    /// Starts the slide effect
    /// </summary>
    _DoSlide : function()
    {
        var newValue = 0;
        var element = null;
        var doNextLoop = true;
        var thisObj = null;
                
        //Get the element
        element = $( this._objId );
        
        //Update the style of the element first
        element.style.display = 'block';
		element.style.visibility = 'visible';
		
		//Get the new Value
		newValue = this._GetElementCurrentValue() + this._currentSpeed;
	    
	    //Check if is already visible to the user
	    if ( newValue > this._originalValue )
	    {
	        newValue = this._originalValue;
	        doNextLoop = false;
	    }
	    //Check if is already not-visible for the user
	    else if ( newValue <= 0 )
	    {
	        newValue = 1;
	        doNextLoop = false;
	    }
	    
	    //Update the element style
	    if ( this.Vertically )
	        element.style.height = newValue + 'px';
	    else
	        element.style.width = newValue + 'px';
	    
	    if ( doNextLoop )
	    {
	        thisObj = this;
	        this.SendMessage('onSlideLooped',{target:this,type:'onSlideLooped'});
	        setTimeout( function() { thisObj._DoSlide(); }, this._timeOut );
	    }
	    else if ( newValue <= 1 )
	    {
	        element.style.display = 'none';
	    }
	    
	    if ( ! doNextLoop )
	        this.SendMessage('onSlideFinished',{target:this,type:'onSlideFinished'});
    } // DoSlide
} // RCSlide.prototype

/****************************************
*               RCFade
*****************************************/

/// <summary>
/// Richer Components - Fade Effect Class
/// </summary>
function RCFade( objId, speed )
{
    this._objId = objId;
    this._speed = speed; // Higher is faster
    this._currentOpacity = 0;
    this._element = null;
    
    this._isIE = ( document.all != null );
} // RCSlide

/// <summary>
/// Richer Components - Fade Effect Class Prototype
/// </summary>
RCFade.prototype = 
{
    /// <summary>
    /// Executes the show command
    /// </summary>
    ExecuteShow : function()
    {
        this.FadeIn();
    }, // ExecuteShow
    
    /// <summary>
    /// Executes the hide command
    /// </summary>
    ExecuteHide : function()
    {
        this.FadeOut();
    }, // ExecuteHide
    
    /// <summary>
    /// Sets the initial opacity of the element
    /// </summary>
    SetInitialOpacity : function( opacity )
    {
        this._currentOpacity = opacity;
    }, // ExecuteHide
    
    /// <summary>
    /// Obtains the target element
    /// </summary>
    _GetElement : function()
    {
        this._element = $( this._objId );
    }, // _GetElement
    
    /// <summary>
    /// Show the object using the fading effect
    /// </summary>
    FadeIn : function()
    {
        var thisObj = null;
        
        //Get the target element
        this._GetElement();
        
        if ( this._currentOpacity <= 100 )
        {
            this._currentOpacity += this._speed;
            
            //Update the style of the element first
            this._element.style.display = 'block';
		    this._element.style.visibility = 'visible';
            
            if ( this._isIE )
                this._element.style.filter = 'alpha(opacity=' + this._currentOpacity + ');'; 
            else
                this._element.style.MozOpacity = this._currentOpacity / 100;
                
            //Go the to next frame
            thisObj = this;
	        setTimeout( function() { thisObj.FadeIn(); }, 0 );
        }
        else
        {
            if ( this._isIE )
                this._element.style.filter = 'alpha(opacity=100);'; 
            else
                this._element.style.MozOpacity = 1;
        }
    }, // FadeIn
    
    /// <summary>
    /// Hide the object using the fading effect
    /// </summary>
    FadeOut : function()
    {
        var thisObj = null;
        
        //Get the target element
        this._GetElement();
        
        if ( this._currentOpacity > 0 )
        {
            this._currentOpacity -= this._speed;
            
            if ( this._isIE )
                this._element.style.filter = 'alpha(opacity=' + this._currentOpacity + ');'; 
            else
                this._element.style.MozOpacity = this._currentOpacity / 100;
                
            //Go the to next frame
            thisObj = this;
	        setTimeout( function() { thisObj.FadeOut(); }, 0 );
        }
        else
        {
            //Update the style of the element first
            this._element.style.display = 'none';
		    
            if ( this._isIE )
                this._element.style.filter = 'alpha(opacity=0);'; 
            else
                this._element.style.MozOpacity = 0;
        }
    } // FadeOut
} // RCFade.prototype

/****************************************
*               RCSlide2
*****************************************/

/// <summary>
/// Richer Components - Slide Effect Class
/// </summary>
function RCSlide2( objId, speed, moveTo )
{
    this._objId = objId;
    this._speed = speed; // Higher is faster
    this._currentSpeed = this._speed;
    this._timeOut = 10; // Lower is faster
    this._executing = false;
    this._moveTo = moveTo;
    this._moveToHigher = false;
    this._listeners = new Array();
    this.Vertically = true;
    
    this.AddListener( this );
} // RCSlide2

/// <summary>
/// Richer Components - Slide Effect Class Prototype
/// </summary>
RCSlide2.prototype = 
{
    /// <summary>
    /// Executes the show command
    /// </summary>
    ExecuteShow : function()
    {
        this._moveToHigher = this._GetElementCurrentValue() < this._moveTo;
    
        this.Show();
    }, // ExecuteShow
    
    /// <summary>
    /// Executes the hide command
    /// </summary>
    ExecuteHide : function()
    {
        this._moveToHigher = this._GetElementCurrentValue() < this._moveTo;
    
        this.Hide();
    }, // ExecuteHide
    
    /// <summary>
    /// Add a new listener
    /// </summary>
    AddListener : function( listener )
    {
        this.RemoveListener( listener );
	    return this._listeners.push( listener );
    }, // AddListener
    
    /// <summary>
    /// Remove the given listener
    /// </summary>
    RemoveListener : function( listener )
    {
        var removed = false;
	    var i = this._listeners.length;
	    
	    while ( i-- && ! removed ) 
	    {
		    if ( this._listeners[i] == listener ) 
		    {
			    this._listeners.splice(i, 1);
			    removed = true;
		    }
	    }
	    
	    return removed;
    }, // RemoveListener
    
    /// <summary>
    /// Send a message to the listeners
    /// </summary>
    SendMessage : function()
    {
        var array = null;
        
        array = new Array();
	    for(var i = 0; i < arguments.length; i++)
	        array.push( arguments[i] );

	    var event = array.shift();	    
	    for (var i = 0; i < this._listeners.length; i++)
	    {
		    if ( this._listeners[i][event] )
		        this._listeners[i][event].apply( this._listeners[i], array );
	    }
    }, // SendMessage
    
    /// <summary>
    /// Lock this instance for executing process
    /// returns true if the lock was successful and false if not
    /// </summary>
    _Lock : function()
    {   
        var locked = false;
        
        //Check for another execution
        if ( ! this._executing )
        {
            //Lock for executing
            this._executing = true;
            locked = true;
        }
        
        return locked;
    }, // _Lock
    
    /// <summary>
    /// Unlock this instance for future process
    /// </summary>
    _Unlock : function()
    {
        this._executing = false;
    }, // _Unlock

    /// <summary>
    /// Shows the slide
    /// </summary>
    Show : function()
    {
        var element = null;
        
        //Try to lock first this process
        if ( this._Lock() )
        {
            this.SendMessage('onSlideStart',{target:this,type:'onSlideStart'});
        
            //Get the element
            element = $( this._objId );
            //Update speed
            this._currentSpeed = this._speed;
            
            this._DoSlide();
            
            //Unlock the process
            this._Unlock();
        }
    }, // Show
    
    /// <summary>
    /// Hide the slide
    /// </summary>
    Hide : function()
    {
        var element = null;
        
        //Try to lock first this process
        if ( this._Lock() )
        {
            //Get the element
            element = $( this._objId );
            //Update speed
            this._currentSpeed = this._speed;
            
            this._DoSlide();
            
            //Unlock the process
            this._Unlock();
        }
    }, // Hide
    
    /// <summary>
    /// Returns the element current height
    /// </summary>
    _GetElementCurrentValue : function ()
    {
        var value = 0;
        var element = null;
        
        //Get the element
        element = $( this._objId );
        
        if ( this.Vertically )
            value = GetTop( element );
        else
            value = GetLeft( element );
	        
	    return value;
    }, // _GetElementCurrentValue
    
    /// <summary>
    /// Starts the slide effect
    /// </summary>
    _DoSlide : function()
    {
        var newValue = 0;
        var element = null;
        var doNextLoop = true;
        var thisObj = null;
                
        //Get the element
        element = $( this._objId );
		
		if ( this._moveToHigher )
		{
		    //Get the new Value
		    newValue = this._GetElementCurrentValue() + this._currentSpeed;
    	    
	        //Check if is already visible to the user
	        if ( newValue >= this._moveTo )
	        {
	            newValue = this._moveTo;
	            doNextLoop = false;
	        }
	    }
	    else
	    {
	        //Get the new Value
		    newValue = this._GetElementCurrentValue() - this._currentSpeed;
		     
	        //Check if is already visible to the user
	        if ( newValue <= this._moveTo )
	        {
	            newValue = this._moveTo;
	            doNextLoop = false;
	        }
	    }
	    
	    //Update the element style
	    if ( this.Vertically )
	        element.style.top = newValue + 'px';
	    else
	        element.style.left = newValue + 'px';
	    
	    if ( doNextLoop )
	    {
	        thisObj = this;
	        this.SendMessage('onSlideLooped',{target:this,type:'onSlideLooped'});
	        setTimeout( function() { thisObj._DoSlide(); }, this._timeOut );
	    }
	    
	    if ( ! doNextLoop )
	        this.SendMessage('onSlideFinished',{target:this,type:'onSlideFinished'});
    } // DoSlide
} // RCSlide.prototype