Rotate the short way

I’m making a Pacman game, and I’m not so good with my first code. I want the Pacman to rotate to the direction to go. Here is my code for that. The hittest is to stop moving if bumping a wall and the curRect variable is the value of the direction to rotate to.


var rotSpeed:Number = 10;
function dirListening(){
    var paNose = returnGlobal(this.packin.nose);
    if(this.dirEcto=="Up"){
        if(!this.wall.hitTest(paNose.x, paNose.y, true)) this.packin._y--;
        this.curRect = -90;
    }
    if(this.dirEcto=="Down"){
        this.curRect = 90;
        if(!this.wall.hitTest(paNose.x, paNose.y, true)) this.packin._y++;
    }
    if(this.dirEcto=="Left"){
        this.curRect = -180;
        if(!this.wall.hitTest(paNose.x, paNose.y, true)) this.packin._x--;
    }
    if(this.dirEcto=="Right"){
        this.curRect = 0;
        if(!this.wall.hitTest(paNose.x, paNose.y, true)) this.packin._x++;
    }
    //turn to rotate
    if(this.curRect != this.packin._rotation)
        this.packin._rotation = this.packin._rotation - rotSpeed;
}

It works just fine, but it only works if I subtract the rotate speed from the rotation. If I try to add the speed to rotation it gets stuck in an infinite spin. So the problem is it will only turn counter clockwise, therefore it will go the long way around like from facing up to facing right. How can I modify the code to go both clockwise directions (the short way) and not get stuck in a spin?