
function moveEffect(instanceName, objectToMove, xBy, yBy, duration1, duration2){
    var _updateInterval = 10;
    
    var _instanceName = instanceName;
    var _objectToMove = objectToMove;
    var _xBy = xBy;    
    var _deltaX;
    var _currentX;
    var _currentDestinationX;
    var _originalX = currentX();
    
     var _yBy = yBy;    
    var _deltaY;
    var _currentY;
    var _currentDestinationY;
    var _originalY = currentY();

    var _moveit1;
    var _moveit2;
    var _isMoving1 = false;
    var _isMoving2 = false;
    
    var _speed1 = duration1 / _updateInterval;
    var _speed2 = duration2 / _updateInterval;
    
    var _isMouseOut = true;
    var _mouseOutDelay = null;
    
    _objectToMove.onmouseover = myTest1;
    _objectToMove.onmouseout = myTest2;
    
    function myTest1(e){
        //alert(e.target.id);
        //if (e.target == _objectToMove)
            startMoving();
            _isMouseOut = false;
    }
    
     function myTest2(e){
        //if (e.target == _objectToMove)
            //startMovingOut();
            _isMouseOut = true;
            if (_mouseOutDelay != null)
                  window.clearTimeout(_mouseOutDelay);
               
            _mouseOutDelay = window.setTimeout(instanceName+".startMovingOut()", 200);
                
    }  

    function startMoving(){      
        if (_isMoving1 == true)
		    return;
		    
		if ( ((currentX() - _originalX ) >= _xBy) && (_xBy > 0) )
		    return;
		if ( ((currentX() - _originalX ) <= _xBy) && (_xBy < 0) )
		    return;
		    
		if (_isMoving2 == true){
		    window.clearInterval(_moveit2);
		    _isMoving2 = false;    
		}
		    
	    _deltaX = _xBy / _speed1 ;	
	    _deltaY = _yBy / _speed1 ;	
	    _currentX = currentX();
	    _currentY = currentY();
	    _currentDestinationX = _originalX + _xBy;
	    _currentDestinationY = _originalY + _yBy;
	    _moveit1=window.setInterval(_instanceName+".easeXY()",_updateInterval);  
        _isMoving1 = true;      
    }
    
    //function startMovingOut(){    
    this.startMovingOut = function (){
        //alert(_isMouseOut);
        if (!_isMouseOut)
            return;
            
            window.clearTimeout(_mouseOutDelay);
            _mouseOutDelay = null;
       
        if (_isMoving2 == true)
		    return;
		    
		if (_isMoving1 == true){
		    window.clearInterval(_moveit1);
		    _isMoving1 = false;    
		}
		    
	    _deltaX = -_xBy / _speed2 ;	
	    _deltaY = -_yBy / _speed2 ;	
	    _currentX = currentX();
	    _currentY = currentY();
	    _currentDestinationX = _originalX;
	    _currentDestinationY = _originalY;
        _moveit2 = window.setInterval(_instanceName+".easeXY()",_updateInterval);        
        _isMoving2 = true;            
          
    }
    
    this.easeXY = function (){
        
        var newX = _currentX + _deltaX;
        var newY = _currentY + _deltaY;
        var finish = false;
        if ( (_deltaX > 0) && (_currentX > _currentDestinationX) ){ 
            finish = true;
	    }
	    else  if ( (_deltaX < 0) && (_currentX < _currentDestinationX) ){ 
	        finish = true;
        }
        else  if ( (_deltaY > 0) && (_currentY > _currentDestinationY) ){ 
            finish = true;
	    }
	    else  if ( (_deltaY < 0) && (_currentY < _currentDestinationY) ){ 
	        finish = true;             
        }
        
        if (finish == true){
            window.clearInterval(_moveit1);
             window.clearInterval(_moveit2);
             _objectToMove.style.marginLeft = _currentDestinationX + 'px';
             _objectToMove.style.marginTop = _currentDestinationY + 'px';
             _isMoving1 = false;       
	         _isMoving2 = false; 
        }
	    else{
	        _objectToMove.style.marginLeft = newX + 'px';
            _currentX = newX;
            
             _objectToMove.style.marginTop = newY + 'px';
            _currentY = newY;
        }
	    
    }
    
    function currentX(){
        var retVal = _objectToMove.style.marginLeft.substring(0, _objectToMove.style.marginLeft.indexOf('px'));        
        return retVal * 1.0;
    }
    
    function currentY(){
        var retVal = _objectToMove.style.marginTop.substring(0, _objectToMove.style.marginTop.indexOf('px'));        
        return retVal * 1.0;
    }
    
}