( AnimationControl = function()
{
    this.STATE_NORMAL = "STATE_NORMAL";
    this.STATE_COMBO = "STATE_COMBO";
    this.STATE_HOME = "STATE_HOME"
    var currentState = this.STATE_NORMAL;
    var playStayAnimation = true;
    var currentCombo
    

    this.update = function( combo )
    {
        currentCombo = combo;
        if ( !playStayAnimation ) return;
        if ( currentCombo >= 10 )
        {
            if ( currentState != this.STATE_COMBO )
            {
                currentState = this.STATE_COMBO;
                this.animStay();
            }
        }
        else if ( currentState != this.STATE_NORMAL )
        {
            currentState = this.STATE_NORMAL;
            this.animStay();
        }
    }

    this.animStay = function()
    {
        if ( currentState == this.STATE_COMBO )
        {
            this.playAnimation( "stay_combo" );
        }
        else if ( currentState == this.STATE_NORMAL )
        {
            this.playAnimation( "stay_normal" );
        }
    }

    this.animBom = function()
    {
        if ( currentState == this.STATE_COMBO ) return;
        playStayAnimation = false;
        this.playAnimation( "bom" );
    }

    this.animLegal = function()
    {
        if ( currentState == this.STATE_COMBO ) return;
        playStayAnimation = false;
        this.playAnimation( "legal" );
    }

    this.animExcelente = function()
    {
        if ( currentState == this.STATE_COMBO ) return;
        playStayAnimation = false;
        this.playAnimation( "excelente" );
    }

    this.playAnimation = function( animName )
    {
        this.anim.gotoAndStop( animName );
    }

    this.endLoop = function()
    {
        playStayAnimation = true;
        if ( currentState == this.STATE_HOME )
        {
            var mc = this.getChildAt( 0 );
            fullStop( mc );
        }
        else
        {
            this.animStay();
        }
    }

    this.setState = function( state )
    {
        currentState = state;
    }

    function fullStop( mc )
    {
        if ( mc.stop ) mc.stop()
        for ( var i = 0; i < mc.children.length; i++ )
        {
            var child = mc.getChildAt( i );
            if ( child.stop ) child.stop()
            if ( child.children ) fullStop( child );
        }
    }

} ).prototype = new createjs.Container();