Degri.MotomanDistance = 0;

Degri.Motoman = function(id)
{
    this.id = id;
    this.direction = "left";

    this.Drive = function()
    {
        var motoman = $("#motoman");
        switch(this.direction)
        {
            case "left":
                //alert($("#motoman img").get().src);
                $("#motoman img").replaceWith("<img src='/img/motomanl.gif' alt=''/>");
                Degri.MotomanDistance = 150;
                //alert(Degri.MotomanDistance);
                motoman.animator(1, this.AnimateLeft);
            break;

            case "right":
                $("#motoman img").replaceWith("<img src='/img/motomanr.gif' alt=''/>");
                Degri.MotomanDistance = 250;
                //alert(Degri.MotomanDistance);
                motoman.animator(1, this.AnimateRight);
            break;
        }

        this.direction = this.direction == "left" ? "right" : "left";
    };
    
    this.AnimateLeft = function(Anim,isEnd)
    {
        newLeft = parseInt(Anim.css("left")) - 1;
        if(isEnd) newLeft = Degri.MotomanDistance;
        Anim.css("left", newLeft);
        return (newLeft > Degri.MotomanDistance);
    };
    
    this.AnimateRight = function(Anim,isEnd)
    {
        newLeft = parseInt(Anim.css("left")) + 1;
        if(isEnd) newLeft = Degri.MotomanDistance;
        Anim.css("left", newLeft);
        return (newLeft < Degri.MotomanDistance);
    };

};

