// Action script...

// [onClipEvent of sprite 5 in frame 1]
onClipEvent (load)
{
    function MoveJ(j)
    {
        this._parent.JVal.val.text = "j=" + j;
        this._parent.JVal._x = ObjArray[j]._x;
        MovePointer(for_j._y);
        if (j > 1)
        {
            moveJ = true;
        } // end if
    } // End of the function
    function MoveI(i)
    {
        this._parent.IVal.val.text = "i=" + i;
        this._parent.IVal._x = ObjArray[i]._x;
        MovePointer(for_i._y);
        if (i > 0)
        {
            moveI = true;
        } // end if
    } // End of the function
    ArrayToSort = new Array(5, 7, 2, 3, 0, 8, 5, 2);
    ObjArray = new Array(this._parent.obj1, this._parent.obj2, this._parent.obj3, this._parent.obj4, this._parent.obj5, this._parent.obj6, this._parent.obj7, this._parent.obj8);
    i = 0;
    j = 0;
    k = 0;
    l = 0;
    MoveJ(j);
    MoveI(i);
    timeToColor = 0;
    timeToColormax = 15;
    timeToMoving = 0;
    timeToMovingmax = 30;
    gotoAndPlay(nextFrame);
    standart = true;
    changePointer = false;
    goToR = false;
    goOutOfR = false;
    changePlace = false;
    counter = 0;
    playingVar = true;
    MovePointer = function (yPos)
    {
        this._parent.pointer._y = yPos;
        return(undefined);
    };
}

onClipEvent (enterFrame)
{
    if (playingVar)
    {
        if (standart)
        {
            j++;
            MoveJ(j);
            if (j > 7 && i < 7)
            {
                i++;
                j = i + 1;
                if (i >= 7)
                {
                    j = 7;
                } // end if
                objColor = new Color(ObjArray[i - 1]);
                transformObject = {ra: 6, rb: 147, aa: 70};
                objColor.setTransform(transformObject);
                MoveI(i);
                MoveJ(j);
            } // end if
            if (i >= 7)
            {
                MoveJ(7);
                return(undefined);
                this._parent.stopScene();
                this._parent.Control.playingVar = false;
                this._parent.pgraph._alpha = 0;
                this._parent.Control._alpha = 0;
            } // end if
            standart = false;
            if (ArrayToSort[i] > ArrayToSort[j])
            {
                MovePointer(this._parent.if_exp._y);
                moving = true;
                temp = ArrayToSort[i];
                ArrayToSort[i] = ArrayToSort[j];
                ArrayToSort[j] = temp;
            } // end if
            trace(ArrayToSort + "i=" + i + ";j=" + j);
        }
        else if (moveJ || moveI)
        {
            if (moveJ)
            {
                counter++;
                MovePointer(this._parent.next_j._y);
                if (counter >= 20)
                {
                    MovePointer(this._parent.for_j._y);
                } // end if
                if (counter >= 40)
                {
                    counter = 0;
                    moveJ = false;
                } // end if
            }
            else
            {
                counter++;
                MovePointer(this._parent.next_i._y);
                if (counter >= 20)
                {
                    MovePointer(this._parent.next_i._y);
                } // end if
                if (counter >= 40)
                {
                    counter = 0;
                    moveI = false;
                } // end if
            } // end if
        }
        else
        {
            ObjArray[i]._alpha = 50;
            ObjArray[j]._alpha = 50;
            k++;
            if (k == -4)
            {
                lenToR = this._parent.r._x - ObjArray[i]._x;
                lenBetween = ObjArray[j]._x - ObjArray[i]._x;
                yToR = this._parent.r._y - ObjArray[i]._y;
                yPos = ObjArray[i]._y;
            } // end if
            if (!moving)
            {
                MovePointer(this._parent.if_exp._y);
                if (k == 15)
                {
                    k = -5;
                    standart = true;
                    ObjArray[i]._alpha = ObjArray[j]._alpha = 100;
                } // end if
            }
            else
            {
                if (k < 0)
                {
                    MovePointer(this._parent.if_exp._y);
                } // end if
                if (k <= 4 && k >= 0)
                {
                    ObjArray[i]._y = ObjArray[i]._y + yToR / 5;
                    MovePointer(this._parent.rmd._y);
                } // end if
                if (k > 4 && k < 14)
                {
                    ObjArray[i]._x = ObjArray[i]._x + lenToR / 9;
                } // end if
                if (k > 14 && k <= 20)
                {
                    MovePointer(this._parent.mdmd._y);
                    ObjArray[j]._y = ObjArray[j]._y + 10;
                } // end if
                if (k > 20 && k <= 30)
                {
                    ObjArray[j]._x = ObjArray[j]._x - lenBetween / 10;
                } // end if
                if (k > 30 && k <= 36)
                {
                    ObjArray[j]._y = ObjArray[j]._y - 10;
                } // end if
                if (k > 36 && k <= 45)
                {
                    MovePointer(this._parent.mdr._y);
                    ObjArray[i]._x = ObjArray[i]._x + (lenBetween - lenToR) / 9;
                } // end if
                if (k > 45 && k <= 50)
                {
                    ObjArray[i]._y = ObjArray[i]._y - yToR / 5;
                } // end if
                if (k == 51)
                {
                    MovePointer(this._parent.end_if._y);
                } // end if
                if (k == 60)
                {
                    standart = true;
                    moving = false;
                    k = -5;
                    ObjArray[i]._alpha = ObjArray[j]._alpha = 100;
                    obj = ObjArray[i];
                    ObjArray[i] = ObjArray[j];
                    ObjArray[j] = obj;
                } // end if
            } // end if
        } // end if
    } // end if
}

// [onClipEvent of sprite 10 in frame 1]
on (release)
{
    if (this._parent.Control.playingVar == true)
    {
        this._parent.Control.playingVar = false;
        this._parent.pgraph._alpha = 0;
        this._parent.sgraph._alpha = 100;
    }
    else
    {
        this._parent.Control.playingVar = true;
        this._parent.sgraph._alpha = 0;
        this._parent.pgraph._alpha = 100;
    } // end if
}

// [onClipEvent of sprite 11 in frame 1]
on (release)
{
    if (this._parent.Control.playingVar == true)
    {
        this._parent.Control.playingVar = false;
        this._parent.pgraph._alpha = 0;
        this._parent.sgraph._alpha = 100;
    }
    else
    {
        this._parent.Control.playingVar = true;
        this._parent.sgraph._alpha = 0;
        this._parent.pgraph._alpha = 100;
    } // end if
}

// [Action in Frame 1]
gotoAndPlay(nextFrame);
