/* Welcome to the Source 

   Organic Harmony 
   Public Domain aniMagix Animation Library Documentation
   http://www.singyfamily.com/Hob/tech/aniMagiX/aniMagiX-how-to.html 

   Copyright is a Human Right  
   Copy -> Mutate -> Create -> Share

*******************************************************************/

//set initial values moved to index.php inline script.
var AMXq = 20;			// Number of Sprites
var images_basic_path = "";	// Path to image directory
var debugAMX = false;		// Debug Output
var Speed = 1.501;	        // Flying Speed	
var Sleeping =300;		// Waiting time
var DeltaH =0;		// Waiting time

//define states & scenarios
function initStates(){

    var rdelay = 0;
    states = new Array;
    
    /*	b0	*/
    st_n = "b0";
    states[ st_n] = new state;
    states[ st_n].onErrorScenario = "eee";
    states[ st_n].z = 100;

    //scenario go north
    //
    states[ st_n ].scenarios["nnn"] = new scenario;

    with (states[ st_n ].scenarios["nnn"]) {
        random_delay = rdelay;

        for (i = 0; i < 10; i++) {
                steps[i] = new step( st_n, "pulse.gif.00" + i, 0, -AMXrnd()*Speed, 20);
        }
        for (i = 10; i < 14; i++) {
                steps[i] = new step( st_n, "pulse.gif.0" + i,  0, -AMXrnd()*Speed, 20);
        }

        i = 0;
        next_scenarios[i++] = new next_scenario("nnn",100);
        next_scenarios[i++] = new next_scenario("nee",100);
        next_scenarios[i++] = new next_scenario("eee",100);
        next_scenarios[i++] = new next_scenario("see",100);
        next_scenarios[i++] = new next_scenario("sss",100);
        next_scenarios[i++] = new next_scenario("wss",100);
        next_scenarios[i++] = new next_scenario("www",100);
        next_scenarios[i++] = new next_scenario("wnn",100);

        next_states[0] = new next_state("b0", "eee", 100);

        ontop_next_states[0] = new next_state("b0", "sss", 100);
        onleft_next_states[0] = new next_state("b0", "eee", 100);
        onright_next_states[0] = new next_state("b0", "www", 100);
        onbottom_next_states[0] = new next_state("b0", "nnn", 100);
    }


    //scenario go north-east
    //
    states[ st_n ].scenarios["nee"] = new scenario;

    with (states[ st_n ].scenarios["nee"]) {
        random_delay = rdelay;

        for (i = 0; i < 10; i++) {
                steps[i] = new step( st_n, "pulse.gif.00" + i,  AMXrnd()*Speed/2, -AMXrnd()*Speed/2, 20);
        }
        for (i = 10; i < 14; i++) {
                steps[i] = new step( st_n, "pulse.gif.0" + i,   AMXrnd()*Speed/2, -AMXrnd()*Speed/2, 20);
        }

        i = 0;
        next_scenarios[i++] = new next_scenario("nnn",100);
        next_scenarios[i++] = new next_scenario("nee",100);
        next_scenarios[i++] = new next_scenario("eee",100);
        next_scenarios[i++] = new next_scenario("see",100);
        next_scenarios[i++] = new next_scenario("sss",100);
        next_scenarios[i++] = new next_scenario("wss",100);
        next_scenarios[i++] = new next_scenario("www",100);
        next_scenarios[i++] = new next_scenario("wnn",100);

        next_states[0] = new next_state("b0", "eee", 100);

        ontop_next_states[0] = new next_state("b0", "sss", 100);
        onleft_next_states[0] = new next_state("b0", "eee", 100);
        onright_next_states[0] = new next_state("b0", "www", 100);
        onbottom_next_states[0] = new next_state("b0", "nnn", 100);
    }


    //scenario go east
    //
    states[ st_n ].scenarios["eee"] = new scenario;

    with (states[ st_n ].scenarios["eee"]) {
        random_delay = rdelay;

	for (i = 0; i < 10; i++) {
        	steps[i] = new step( st_n, "pulse.gif.00" + i, AMXrnd()*Speed,   0, 20);
	}
	for (i = 10; i < 14; i++) {
        	steps[i] = new step( st_n, "pulse.gif.0" + i,  AMXrnd()*Speed,   0, 20);
	}

	i = 0;
        next_scenarios[i++] = new next_scenario("nnn",100);
        next_scenarios[i++] = new next_scenario("nee",100);
        next_scenarios[i++] = new next_scenario("eee",100);
        next_scenarios[i++] = new next_scenario("see",100);
        next_scenarios[i++] = new next_scenario("sss",100);
        next_scenarios[i++] = new next_scenario("wss",100);
        next_scenarios[i++] = new next_scenario("www",100);
        next_scenarios[i++] = new next_scenario("wnn",100);

        next_states[0] = new next_state("b0", "eee", 100);

        ontop_next_states[0] = new next_state("b0", "sss", 100);
        onleft_next_states[0] = new next_state("b0", "eee", 100);
        onright_next_states[0] = new next_state("b0", "www", 100);
        onbottom_next_states[0] = new next_state("b0", "nnn", 100);
    }
       //

   //scenario go south east
    //
    states[ st_n ].scenarios["see"] = new scenario;

    with (states[ st_n ].scenarios["see"]) {
        random_delay = rdelay;

        for (i = 0; i < 10; i++) {
                steps[i] = new step( st_n, "pulse.gif.00" + i, AMXrnd()*Speed/2,   AMXrnd()*Speed/2, 20);
        }
        for (i = 10; i < 14; i++) {
                steps[i] = new step( st_n, "pulse.gif.0" + i,  AMXrnd()*Speed/2,   AMXrnd()*Speed/2, 20);
        }

        i = 0;
        next_scenarios[i++] = new next_scenario("nnn",100);
        next_scenarios[i++] = new next_scenario("nee",100);
        next_scenarios[i++] = new next_scenario("eee",100);
        next_scenarios[i++] = new next_scenario("see",100);
        next_scenarios[i++] = new next_scenario("sss",100);
        next_scenarios[i++] = new next_scenario("wss",100);
        next_scenarios[i++] = new next_scenario("www",100);
        next_scenarios[i++] = new next_scenario("wnn",100);

        next_states[0] = new next_state("b0", "eee", 100);

        ontop_next_states[0] = new next_state("b0", "sss", 100);
        onleft_next_states[0] = new next_state("b0", "eee", 100);
        onright_next_states[0] = new next_state("b0", "www", 100);
        onbottom_next_states[0] = new next_state("b0", "nnn", 100);
    }
       //

    //scenario go south
    //
    states[ st_n ].scenarios["sss"] = new scenario;

    with (states[ st_n ].scenarios["sss"]) {
        random_delay = rdelay;

        for (i = 0; i < 10; i++) {
                steps[i] = new step( st_n, "pulse.gif.00" + i, 0, AMXrnd()*Speed, 20);
        }
        for (i = 10; i < 14; i++) {
                steps[i] = new step( st_n, "pulse.gif.0" + i,  0, AMXrnd()*Speed, 20);
        }

        i = 0;
        next_scenarios[i++] = new next_scenario("nnn",100);
        next_scenarios[i++] = new next_scenario("nee",100);
        next_scenarios[i++] = new next_scenario("eee",100);
        next_scenarios[i++] = new next_scenario("see",100);
        next_scenarios[i++] = new next_scenario("sss",100);
        next_scenarios[i++] = new next_scenario("wss",100);
        next_scenarios[i++] = new next_scenario("www",100);
        next_scenarios[i++] = new next_scenario("wnn",100);

        next_states[0] = new next_state("b0", "eee", 100);

        ontop_next_states[0] = new next_state("b0", "sss", 100);
        onleft_next_states[0] = new next_state("b0", "eee", 100);
        onright_next_states[0] = new next_state("b0", "www", 100);
        onbottom_next_states[0] = new next_state("b0", "nnn", 100);
    }

 
    //scenario wss back
    //
    states[ st_n ].scenarios["wss"] = new scenario;
    with (states[ st_n ].scenarios["wss"]) {
        random_delay = rdelay;
	
	for (i = 0; i < 10; i++) {
        	steps[i] = new step( st_n, "pulse.gif.00" + i, -AMXrnd()*Speed/2,  AMXrnd()*Speed/2, 2);
	}
	for (i = 10; i < 14; i++) {
        	steps[i] = new step( st_n, "pulse.gif.0" + i, -AMXrnd()*Speed/2,  AMXrnd()*Speed/2, 2);
	}


	i = 0;
        next_scenarios[i++] = new next_scenario("nnn",100);
        next_scenarios[i++] = new next_scenario("nee",100);
        next_scenarios[i++] = new next_scenario("eee",100);
        next_scenarios[i++] = new next_scenario("see",100);
        next_scenarios[i++] = new next_scenario("sss",100);
        next_scenarios[i++] = new next_scenario("wss",100);
        next_scenarios[i++] = new next_scenario("www",100);
        next_scenarios[i++] = new next_scenario("wnn",100);

        next_states[0] = new next_state("b0", "wss", 100);

        ontop_next_states[0] = new next_state("b0", "sss", 100);
        onleft_next_states[0] = new next_state("b0", "eee", 100);
        onright_next_states[0] = new next_state("b0", "www", 100);
        onbottom_next_states[0] = new next_state("b0", "nnn", 100);
    }

    //scenario www back
    //
    states[ st_n ].scenarios["www"] = new scenario;
    with (states[ st_n ].scenarios["www"]) {
        random_delay = rdelay;

        for (i = 0; i < 10; i++) {
                steps[i] = new step( st_n, "pulse.gif.00" + i, -AMXrnd()*Speed,  0, 2);
        }
        for (i = 10; i < 14; i++) {
                steps[i] = new step( st_n, "pulse.gif.0" + i, -AMXrnd()*Speed,  0, 2);
        }


        i = 0;
        next_scenarios[i++] = new next_scenario("nnn",100);
        next_scenarios[i++] = new next_scenario("nee",100);
        next_scenarios[i++] = new next_scenario("eee",100);
        next_scenarios[i++] = new next_scenario("see",100);
        next_scenarios[i++] = new next_scenario("sss",100);
        next_scenarios[i++] = new next_scenario("wss",100);
        next_scenarios[i++] = new next_scenario("www",100);
        next_scenarios[i++] = new next_scenario("wnn",100);

        next_states[0] = new next_state("b0", "www", 100);

        ontop_next_states[0] = new next_state("b0", "sss", 100);
        onleft_next_states[0] = new next_state("b0", "eee", 100);
        onright_next_states[0] = new next_state("b0", "www", 100);
        onbottom_next_states[0] = new next_state("b0", "nnn", 100);
    }

 //scenario wwn back
    //
    states[ st_n ].scenarios["wnn"] = new scenario;
    with (states[ st_n ].scenarios["wnn"]) {
        random_delay = rdelay;

        for (i = 0; i < 10; i++) {
                steps[i] = new step( st_n, "pulse.gif.00" + i, -AMXrnd()*Speed/2,   -AMXrnd()*Speed/2, 2);
        }
        for (i = 10; i < 14; i++) {
                steps[i] = new step( st_n, "pulse.gif.0" + i, -AMXrnd()*Speed/2,   -AMXrnd()*Speed/2, 2);
        }

        i = 0;
        next_scenarios[i++] = new next_scenario("nnn",100);
        next_scenarios[i++] = new next_scenario("nee",100);
        next_scenarios[i++] = new next_scenario("eee",100);
        next_scenarios[i++] = new next_scenario("see",100);
        next_scenarios[i++] = new next_scenario("sss",100);
        next_scenarios[i++] = new next_scenario("wss",100);
        next_scenarios[i++] = new next_scenario("www",100);
        next_scenarios[i++] = new next_scenario("wnn",100);

        next_states[0] = new next_state("b0", "wnn", 100);

        ontop_next_states[0] = new next_state("b0", "sss", 100);
        onleft_next_states[0] = new next_state("b0", "eee", 100);
        onright_next_states[0] = new next_state("b0", "www", 100);
        onbottom_next_states[0] = new next_state("b0", "nnn", 100);
    }

    checkStatus("b0","");    
}


//initialize sprites
function setSpriteObjects(){

    for (i=0;i<AMXq;i++){
	AMXs[i]=new sprite('b0', 'eee', 320, 200, states['b0'].z , 0, 0, win_width-50, win_height-50);
    }
}

