/**
 * @author fordenbacs
 */     
//  game
// changes 12/27/07 



 // move this stuff out to game. settings
var bullets = new Array();
var bs = new Array();
// these are game variables
var lv = new Array();

lv[0] = new level_settings();
lv[1] = new level_settings();
lv[2] = new level_settings();
	
var valuables=new Array();
var hostiles=new Array();
var vostiles=new Array();
var targets=new Array();
var hs=new Array();

var helper_target=0;

var game_difficulty;
var life_loss_num_fires=2;
var life_loss_counter=0;

var res=0;
var scoreText;	

var myInterface;
var firekey;

var q = 0;
var origlives=0;
var hookonce='no';
var started='no';
var in_levels_interlude = 'no';
var in_lives_interlude = 'no';
var in_levels_interlude_ctr = 0;
var in_lives_interlude_ctr = 0;

var myDir=0;

var trail=new Array();
var trailIX=0;

function SF_game(

	in_hostile_dir,
	
	in_vostile_dir,
	
	in_valuable_dir

	
	
) {
	t=this;

	t.in_hostile_dir=in_hostile_dir;

	t.in_vostile_dir=in_vostile_dir;	
	
	t.in_valuable_dir=in_valuable_dir;
	
	
	
	
	t.meanies=new Array();
	t.meanies_path=new Array();
	t.meanies_direct=new Array();
	t.meanies_cdir=new Array();
	t.mn=new Array();
	t.entourage=new Array();
	
	//marketing
	//t.message=new Array();
		
	return t;						
};

function level_set_0() {

 	lv[0].num_valuables=game.lv_easy_num_valuables;	
 	lv[0].valuable_points=game.lv_easy_valuable_points;	

 	lv[0].valuable_speed_seed=game.lv_easy_valuable_speed_seed;
 	lv[0].valuable_speed_adder=game.lv_easy_valuable_speed_adder;	
	
	lv[0].num_hostiles=game.lv_easy_num_hostiles;
 	lv[0].hostile_points=game.lv_easy_hostile_points;
 	lv[0].hostile_speed_seed=game.lv_easy_hostile_speed_seed;
 	lv[0].hostile_speed_adder=game.lv_easy_hostile_speed_adder;		
	
	lv[0].num_vostiles=game.lv_easy_num_vostiles;
 	lv[0].vostile_points=game.lv_easy_vostile_points;
 	lv[0].vostile_speed_seed=game.lv_easy_vostile_speed_seed;
 	lv[0].vostile_speed_adder=game.lv_easy_vostile_speed_adder;	
		
 	lv[0].num_targets=game.lv_easy_num_targets;
 	lv[0].target_points=game.lv_easy_target_points;

 	lv[0].num_meanies=game.lv_easy_num_meanies;
 	lv[0].has_entourage=game.lv_easy_has_entourage;
	lv[0].num_followers=game.lv_easy_num_followers;
		

};	

function level_bump_0() {

	var thebump=Math.round(game.level*game.lv_easy_num_valuables_bump);	
 	lv[0].num_valuables=lv[0].num_valuables+thebump;	
 	lv[0].valuable_speed_seed=lv[0].valuable_speed_seed+game.lv_easy_valuable_speed_seed_bump;
 	lv[0].valuable_speed_adder=lv[0].valuable_speed_adder+game.lv_easy_valuable_speed_adder_bump;	

	thebump=Math.round(game.level*game.lv_easy_num_hostiles_bump);		
	lv[0].num_hostiles=lv[0].num_hostiles+thebump;
 	lv[0].hostile_speed_seed=lv[0].hostile_speed_seed+game.lv_easy_hostile_speed_seed_bump;
 	lv[0].hostile_speed_adder=lv[0].hostile_speed_adder+game.lv_easy_hostile_speed_adder_bump;		

	thebump=Math.round(game.level*game.lv_easy_num_vostiles_bump);
	lv[0].num_vostiles=lv[0].num_vostiles+thebump;
 	lv[0].vostile_speed_seed=lv[0].vostile_speed_seed+game.lv_easy_vostile_speed_seed_bump;
 	lv[0].vostile_speed_adder=lv[0].vostile_speed_adder+game.lv_easy_vostile_speed_adder_bump;		

    if (game.lv_easy_num_targets_bump == 0) {
		thebump=Math.round(game.level*game.lv_easy_num_targets_bump);
	 	lv[0].num_targets=lv[0].num_targets+thebump;
	}
};

function level_set_1() {	

	lv[1].num_valuables=game.lv_medium_num_valuables;
	lv[1].valuable_points=game.lv_medium_valuable_points;	;	

	lv[1].valuable_speed_seed=game.lv_medium_valuable_speed_seed;
	lv[1].valuable_speed_adder=game.lv_medium_valuable_speed_adder;
	
	lv[1].num_hostiles=game.lv_medium_num_hostiles;
	lv[1].hostile_points=game.lv_medium_hostile_points;
	lv[1].hostile_speed_seed=game.lv_medium_hostile_speed_seed;
	lv[1].hostile_speed_adder=game.lv_medium_hostile_speed_adder;	

	lv[1].num_vostiles=game.lv_medium_num_vostiles;
	lv[1].vostile_points=game.lv_medium_vostile_points;
	lv[1].vostile_speed_seed=game.lv_medium_vostile_speed_seed;
	lv[1].vostile_speed_adder=game.lv_medium_vostile_speed_adder;	
		
	lv[1].num_targets=game.lv_medium_num_targets;
	lv[1].target_points=game.lv_medium_target_points;

 	lv[1].num_meanies=game.lv_medium_num_meanies;
 	lv[1].has_entourage=game.lv_medium_has_entourage;
	lv[1].num_followers=game.lv_medium_num_followers;
		
};

function level_bump_1() {
	
	var thebump=Math.round(game.level*game.lv_medium_num_valuables_bump);	
 	lv[1].num_valuables=lv[1].num_valuables+thebump;	
 	lv[1].valuable_speed_seed=lv[1].valuable_speed_seed+game.lv_medium_valuable_speed_seed_bump;
 	lv[1].valuable_speed_adder=lv[1].valuable_speed_adder+game.lv_medium_valuable_speed_adder_bump;	
	
	thebump=Math.round(game.level*game.lv_medium_num_hostiles_bump);	
	lv[1].num_hostiles=lv[1].num_hostiles+thebump;
 	lv[1].hostile_speed_seed=lv[1].hostile_speed_seed+game.lv_medium_hostile_speed_seed_bump;
 	lv[1].hostile_speed_adder=lv[1].hostile_speed_adder+game.lv_medium_hostile_speed_adder_bump;		

	thebump=Math.round(game.level*game.lv_medium_num_vostiles_bump);	
	lv[1].num_vostiles=lv[1].num_vostiles+thebump;
 	lv[1].vostile_speed_seed=lv[1].vostile_speed_seed+game.lv_medium_vostile_speed_seed_bump;
 	lv[1].vostile_speed_adder=lv[1].vostile_speed_adder+game.lv_medium_vostile_speed_adder_bump;		

    if (game.lv_medium_num_targets_bump == 0) {
		thebump=Math.round(game.level*game.lv_medium_num_targets_bump);	
	 	lv[1].num_targets=lv[1].num_targets+thebump;
    }

};

function level_set_2() {

	lv[2].num_valuables=game.lv_hard_num_valuables;
	lv[2].valuable_points=game.lv_hard_valuable_points;	;	

	lv[2].valuable_speed_seed=game.lv_hard_valuable_speed_seed;
	lv[2].valuable_speed_adder=game.lv_hard_valuable_speed_adder;
			
	lv[2].num_hostiles=game.lv_hard_num_hostiles;
	lv[2].hostile_points=game.lv_hard_hostile_points;
	lv[2].hostile_speed_seed=game.lv_hard_hostile_speed_seed;
	lv[2].hostile_speed_adder=game.lv_hard_hostile_speed_adder;	
			
	lv[2].num_vostiles=game.lv_hard_num_vostiles;
	lv[2].vostile_points=game.lv_hard_vostile_points;
	lv[2].vostile_speed_seed=game.lv_hard_vostile_speed_seed;
	lv[2].vostile_speed_adder=game.lv_hard_vostile_speed_adder;	
		
	lv[2].num_targets=game.lv_hard_num_targets;
	lv[2].target_points=game.lv_hard_target_points;

 	lv[2].num_meanies=game.lv_hard_num_meanies;
 	lv[2].has_entourage=game.lv_hard_has_entourage;
	lv[2].num_followers=game.lv_hard_num_followers;
		

};

function level_bump_2() {

	var thebump=Math.round(game.level*game.lv_hard_num_valuables_bump);	
 	lv[2].num_valuables=lv[2].num_valuables+thebump;	
 	lv[2].valuable_speed_seed=lv[2].valuable_speed_seed+game.lv_hard_valuable_speed_seed_bump;
 	lv[2].valuable_speed_adder=lv[2].valuable_speed_adder+game.lv_hard_valuable_speed_adder_bump;	

	thebump=Math.round(game.level*game.lv_hard_num_hostiles_bump);	
	lv[2].num_hostiles=lv[2].num_hostiles+thebump;
 	lv[2].hostile_speed_seed=lv[2].hostile_speed_seed+game.lv_hard_hostile_speed_seed_bump;
 	lv[2].hostile_speed_adder=lv[2].hostile_speed_adder+game.lv_hard_hostile_speed_adder_bump;		

	thebump=Math.round(game.level*game.lv_hard_num_vostiles_bump);
	lv[2].num_vostiles=lv[2].num_vostiles+thebump;
 	lv[2].vostile_speed_seed=lv[2].vostile_speed_seed+game.lv_hard_vostile_speed_seed_bump;
 	lv[2].vostile_speed_adder=lv[2].vostile_speed_adder+game.lv_hard_vostile_speed_adder_bump;		

    if (game.lv_hard_num_targets_bump == 0) {
		thebump=Math.round(game.level*game.lv_hard_num_targets_bump);
 		lv[2].num_targets=lv[2].num_targets+thebump;
 	}

};

function meanie_status(in_counter, in_cdir, in_direct, in_path) {
	t=this;
	t.counter = in_counter;
	t.cdir = in_cdir;
	t.direct = in_direct;
	t.path = in_path;
	return t;
};

function target_status(in_hit, in_onfire, in_burning) {
	this.hit = in_hit;
	this.onfire = in_onfire;
	this.burning = in_burning;
};

function helper_status(in_state, in_target, in_shortest, in_gotox, in_gotoy) {
	this.state = in_state;
	this.target = in_target;
	this.shortest = in_shortest;
	this.gotox = in_gotox;
	this.gotoy = in_gotoy;
};

function level_settings(

	in_num_valuables,
	in_valuable_points,
	in_valuable_speed_seed, 
	in_valuable_speed_adder,
	
	in_num_hostiles,
	in_hostile_points, 
	in_hostile_speed_seed,
	in_hostile_speed_adder,
	
	in_num_vostiles,
	in_vostile_points, 
	in_vostile_speed_seed,
	in_vostile_speed_adder,
		
	in_num_targets,
	in_target_points,
	
	in_num_meanies
	

) {
	
	this.num_valuables=in_num_valuables;
	this.valuable_points=in_valuable_points;
	this.valuable_speed_seed=in_valuable_speed_seed;
	this.valuable_speed_adder=in_valuable_speed_adder;
	
	this.num_targets=in_num_targets;
	this.target_points=in_target_points;
		
	this.num_hostiles=in_num_hostiles;
	this.hostile_points=in_hostile_points;
	this.hostile_speed_seed=in_hostile_speed_seed;
	this.hostile_speed_adder=in_hostile_speed_adder;

	this.num_vostiles=in_num_vostiles;
	this.vostile_points=in_vostile_points;
	this.vostile_speed_seed=in_vostile_speed_seed;
	this.vostile_speed_adder=in_vostile_speed_adder;
		
	this.num_meanies=in_num_meanies;

};




// Position is an object used to hold a sprite position+rotation. No methods.
function Position(x,y,r){
	this.x=x;
	this.y=y;
	this.r=r;
}



function gtypeoverrides(){
 	switch(game.gtype) {
 	    case 'Classic':
			game.hostile_points=250;
			game.valuable_points=100;
			game.vostile_points=250;
			game.canshootvostile='yes';
			lv[0].num_targets=0;
			lv[1].num_targets=0;
			lv[2].num_targets=0;
			lv[0].num_targets_bump=0;
			lv[1].num_targets_bump=0;
			lv[2].num_targets_bump=0;
		    break; 
   		case 'Shooting Gallery':
			game.valuable_dir='left to right';
			game.hostile_dir='left to right'; 
			game.canshoothostile='yes';
			game.canshootvaluables='yes';
			//when shoot vostile, loss of life
			game.canshootvostile='yes';
			game.canshoottarget='no';
			game.hostile_points=250;
			game.valuable_points=100;
		    break; 
   		case 'Shooting Ball':
			game.valuable_dir='left to right';
			game.hostile_dir='left to right'; 
			game.canshoothostile='no';
			game.canshootvaluables='no';
			game.canshootvostile='no';
			game.canshoottarget='yes';
			game.num_bullets=1;
		    break; 
   		case 'Bomb Drop':
			game.valuable_dir='left to right';
			game.hostile_dir='left to right'; 
			game.vostile_dir='bottom to top';
			game.canshoothostile='yes';
			game.canshootvaluables='yes';
			game.canshootvostile='no';
			game.canshoottarget='no';
		    break; 
   		case 'Catching Things':
			game.hostile_dir='top to bottom'; 
			game.canshoothostile='no';
			game.canshootvaluables='no';
			game.canshootvostile='no';
			game.canshoottarget='no';
			lv[0].num_vostiles=4;
			lv[1].num_vostiles=5;
			lv[2].num_vostiles=6;
			lv[0].num_valuables=1;
			lv[1].num_valuables=2;
			lv[2].num_valuables=3;
			lv[0].num_hostiles=1;
			lv[1].num_hostiles=2;
			lv[2].num_hostiles=3;
	} 
};

function directions_on() {

	if ((game.gtype == 'Classic') || 
	   (game.gtype == 'Shooting Gallery') ||
	   (game.gtype == 'Shooting Ball') ||
	   (game.gtype == 'Catching Things')) 	 { 
	
	    if (game.gtype == 'Classic') {
			var dir1='<span class="styleInfo">The HERO of the game, follows the mouse. Click mouse to shoot.</span>';
		}
	    if (game.gtype == 'Shooting Gallery') {
			var dir1='<span class="styleInfo">The HERO of the game, follows the mouse. Click mouse to shoot.</span>';
		}
		if (game.gtype == 'Shooting Ball') {
			var dir1='<span class="styleInfo">The HERO of the game, follows the mouse. Click mouse to shoot.</span>';
		}
		if (game.gtype == 'Catching Things') {
			var dir1='<span class="styleInfo">The HERO of the game, follows the mouse.</span>';
		}
		dir1Text=new Gl_layer(185,80,380,dir1);
		dir1Text.show();	
		dhero=new Sp_Sprite();
		dhero.setImage(game.hero_image,game.hero_width,game.hero_height,1,1);
		dhero.setXlimits(game.hero_x_limit_left,game.hero_x_limit_right);	
		dhero.setYlimits(game.hero_y_limit_top,game.hero_y_limit_bottom);
		dhero.setFrame(0);		
		dhero.setAnimationLoop(0,1);	
		dhero.setAnimationSpeed(2,"forward"); 
		dhero.setAnimation(0);	
		dhero.setSpeed(4);		
		dhero.setAnimationRepeat(-1);	
		dhero.collides=true;
		dhero.useHitEvents(true);
	    dhero.moveTo(100,80);
		dhero.switchOn();
	
	}

	if ((game.gtype == 'Classic') || 
	   (game.gtype == 'Shooting Gallery') ||
	   (game.gtype == 'Shooting Ball') ||
	   (game.gtype == 'Catching Things')) 	 {  
	    	if (game.gtype == 'Classic') {
				var dir2='<span class="styleInfo">The big prize of the game, run into it with your hero for big points.</span>';
			}
	    	if (game.gtype == 'Shooting Gallery') {
				var dir2='<span class="styleInfo">The big prize of the game, shoot them for big points.</span>';
			}
			if (game.gtype == 'Shooting Ball') {
				var dir2='<span class="styleInfo">This guy is between your and the target at the top, do not hit it.</span>';
			}
			if (game.gtype == 'Catching Things') {
				var dir2='<span class="styleInfo">The big prize of the game, catch them with your HERO for big points. Do not let them reach the bottom or you lose life.</span>';
			}
			dir2Text=new Gl_layer(185,180,380,dir2);
			dir2Text.show();
			dhostiles=new Sp_Sprite();	
			dhostiles.setImage(game.hostile_image,game.hostile_width,game.hostile_height,1,1); 
			dhostiles.setXlimits(100,game.screen_width+100);	
			dhostiles.setYlimits(50,game.screen_height+50);	
			dhostiles.setFrame(0);		
			dhostiles.setAnimationLoop(0,1);	
			dhostiles.setAnimationSpeed(2,"forward"); 
			dhostiles.setAnimation(0);	
			dhostiles.setSpeed(4);		
			dhostiles.setAnimationRepeat(-1);	
			//dhostiles.collides=true;
			//dhostiles.useHitEvents(true);
			dhostiles.moveTo(100,180);
			dhostiles.switchOn();

}

	if ((game.gtype == 'Classic') || 
	   (game.gtype == 'Shooting Gallery') ||
	   (game.gtype == 'Shooting Ball') ||
	   (game.gtype == 'Catching Things')) 	 {  	
	    
		if (game.gtype == 'Classic') {    
			var dir3='<span class="styleInfo">The small prize of the game, run into it with your hero for small points.</span>';
		}
		if (game.gtype == 'Shooting Gallery') {    
			var dir3='<span class="styleInfo">The small prize of the game, shoot them for small points.</span>';
		}
		if (game.gtype == 'Shooting Ball') {    
			var dir3='<span class="styleInfo"></span>';
		}
		if (game.gtype == 'Catching Things') {
				var dir3='<span class="styleInfo">The small prize of the game, catch them with your HERO for small points.  Do not let them reach the bottom or you lose life.</span>';
		}
		if (game.gtype != 'Shooting Ball') {
			dir3Text=new Gl_layer(185,260,380,dir3);
			dir3Text.show();
			dvaluable=new Sp_Sprite();	
			dvaluable.setImage(game.valuable_image,game.valuable_width,game.valuable_height,1,1); 
			dvaluable.setXlimits(100,game.screen_width+100);	
			dvaluable.setYlimits(50,game.screen_height+50);	
			dvaluable.setFrame(0);		
			dvaluable.setAnimationLoop(0,1);	
			dvaluable.setAnimationSpeed(2,"forward"); 
			dvaluable.setAnimation(0);	
			dvaluable.setSpeed(4);		
			dvaluable.setAnimationRepeat(-1);	
			dvaluable.setDir(0,0);
			//dvaluable.collides=true;
			//dvaluable.useHitEvents(true);
			dvaluable.moveTo(100,260);
			dvaluable.switchOn();
		}
	}
	
	if ((game.gtype == 'Classic') || 
	   (game.gtype == 'Shooting Gallery') ||
	   (game.gtype == 'Shooting Ball') ||
	   (game.gtype == 'Catching Things')) 	 { 
	        if (game.gtype == 'Classic') { 
				var dir4='<span class="styleInfo">The bad guy of the game, shoot him or avoid him.</span>';
			}
	        if (game.gtype == 'Shooting Gallery') { 
				var dir4='<span class="styleInfo">The bad guy of the game, avoid him! If you shoot him, you lose a life!</span>';
			}
			if (game.gtype == 'Shooting Ball') { 
				var dir4='<span class="styleInfo"></span>';
			}		
	        if (game.gtype == 'Catching Things') { 
				var dir4='<span class="styleInfo">The bad guy of the game, avoid him!</span>';
			}	
			if (game.gtype != 'Shooting Ball') {		
				dir4Text=new Gl_layer(185,340,380,dir4);
				dir4Text.show();
				dvostiles=new Sp_Sprite();	
				dvostiles.setImage(game.vostile_image,game.vostile_width,game.vostile_height,1,1); 
				dvostiles.setXlimits(100,game.screen_width+100);	
				dvostiles.setYlimits(50,game.screen_height+50);	
				dvostiles.setFrame(0);		
				dvostiles.setAnimationLoop(0,1);	
				dvostiles.setAnimationSpeed(2,"forward"); 
				dvostiles.setAnimation(0);	
				dvostiles.setSpeed(4);		
				dvostiles.setAnimationRepeat(-1);	
				//dvostiles.collides=true;
				//dvostiles.useHitEvents(true);
				dvostiles.moveTo(100,340);
				dvostiles.switchOn();
			}	
	}

	if ((game.gtype == 'Classic') || 
	   (game.gtype == 'Shooting Galleryzxxxx')) 	 { 
		if (game.gtype == 'Classic') { 	
			var dir5='<span class="styleInfo">The Meanie of the game, avoid him!</span>';
		}
		dir5Text=new Gl_layer(185,420,380,dir5);
		dir5Text.show();
		dmeanie=new Sp_Sprite();	
		dmeanie.setImage(game.meanie_image,game.meanie_width,game.meanie_height,1,1); 
		dmeanie.setXlimits(100,game.screen_width+100);	
		dmeanie.setYlimits(50,game.screen_height+50);	
		dmeanie.setFrame(0);		
		dmeanie.setAnimationLoop(0,1);	
		dmeanie.setAnimationSpeed(2,"forward"); 
		dmeanie.setAnimation(0);	
		dmeanie.setSpeed(4);		
		dmeanie.setAnimationRepeat(-1);	
		//dmeanie.collides=true;
		//dmeanie.useHitEvents(true);
		dmeanie.moveTo(100,420);
		dmeanie.switchOn();	
	}
	
};
 
 function directions_off() {
  	if ((game.gtype == 'Classic') || 
	   (game.gtype == 'Shooting Gallery') ||
	   (game.gtype == 'Bomb Drop') ||
	   (game.gtype == 'Catching Things')) 	 { 
		 	dhero.switchOff();
			dir1Text.hide();
			dhostiles.switchOff();
			dir2Text.hide();
			dvaluable.switchOff();
			dir3Text.hide();
			dvostiles.switchOff();
			dir4Text.hide();
	}
	
  	if ((game.gtype == 'Classic') || 
	   (game.gtype == 'Shooting Gallery') ||
	   (game.gtype == 'Bomb Drop')) { 		
			dmeanie.switchOff();
			dir5Text.hide();
	}
		
  	if (game.gtype == 'Shooting Ball') { 		
		 	dhero.switchOff();
			dir1Text.hide();
			dhostiles.switchOff();
			dir2Text.hide();
	}			
 };
 
function load_game_init(){


Sp_linuxcompatible=true;


//set marketing message from json string

var fobj = Json.evaluate(fo);
game.abc001=bdc(fobj.ba);
game.def002=bdc(fobj.bb);
game.ghi003=new Array();
game.ghi003[1]=bdc(fobj.fa);
game.ghi003[2]=bdc(fobj.fb);
game.ghi003[3]=bdc(fobj.fc);
game.ghi003[4]=bdc(fobj.fd);
game.ghi003[5]=bdc(fobj.fe);
game.ghi003[6]=bdc(fobj.ff);
game.ghi003[7]=bdc(fobj.fg);
game.ghi003[8]=bdc(fobj.fh);
game.ghi003[9]=bdc(fobj.fi);
game.ghi003[10]=bdc(fobj.fj);
game.hero_image=bdc(fobj.ga);
game.hero_height=bdc(fobj.gaa);
game.hero_width=bdc(fobj.gab);

game.helper_image=bdc(fobj.gb);
game.helper_height=bdc(fobj.gba);
game.helper_width=bdc(fobj.gbb);

game.hostile_image=bdc(fobj.gc);
game.hostile_height=bdc(fobj.gca);
game.hostile_width=bdc(fobj.gcb);

game.vostile_image=bdc(fobj.gd);
game.vostile_height=bdc(fobj.gda);
game.vostile_width=bdc(fobj.gdb);

game.valuable_image=bdc(fobj.ge);
game.valuable_height=bdc(fobj.gea);
game.valuable_width=bdc(fobj.geb);

game.meanie_image=bdc(fobj.gf);
game.meanie_height=bdc(fobj.gfa);
game.meanie_width=bdc(fobj.gfb);

game.target_image=bdc(fobj.gg);
game.target_height=bdc(fobj.gga);
game.target_width=bdc(fobj.ggb);

game.bullet_image=bdc(fobj.gh);
game.bullet_height=bdc(fobj.gha);
game.bullet_width=bdc(fobj.ghb);

game.gtype=bdc(fobj.taa);


// at the moment these are not coming in from the url, but eventually may.
//set defaults
game.score = 0;
game.level = 1;
game.game_levels = 10;
game.lives = 10;
game.level_frames = 400;
game.count_frames = 0;
game.life_bonus_num_points=25000;
game.life_next_bonus=25000;
game.on_fire_time=100;

game.num_bullets = 5;
game.canshootvostile='yes';
game.vostile_points=5000;
game.canshoothostile='no';
game.hostile_points=1000;
game.canshootvaluables='no';
game.valuable_points=100;
game.sound_0='../sound/clk.wav';
game.sound_1='../sound/xphone13.wav';
game.easy_image='wimages/easy.gif';
game.medium_image='wimages/medium.gif';
game.hard_image='wimages/hard.gif';
game.screen_width=500;
game.screen_height=500;
game.score_text='Score';
game.level_text='Level';
game.lives_text='Lives';
game.frames_text='Frames';
game.lost_life_text='Lost Life';
game.new_level_text='New Level';
// length of interlude
game.lost_life_duration=10;
game.new_level_duration=50;
game.hero_start_x=350;
game.hero_start_y=400;
game.hero_x_limit_left=100;
game.hero_x_limit_right=600;
game.hero_y_limit_top=50;
game.hero_y_limit_bottom=550;
game.targets_x_limit_left=100;
game.targets_x_limit_right=600;
game.targets_y_limit_top=500;
game.targets_y_limit_bottom=525;
game.helper_start_x=110;
game.helper_start_y=510;
game.follower_distance=20;
game.follower_trail_array_size=200;


game.lv_easy_num_valuables=2;
game.lv_easy_valuable_points=25;
game.lv_easy_valuable_speed_seed=2;
game.lv_easy_valuable_speed_adder=0;
game.lv_easy_num_hostiles=2;
game.lv_easy_hostile_points=250;
game.lv_easy_hostile_speed_seed=2;
game.lv_easy_hostile_speed_adder=1;
game.lv_easy_num_vostiles=2;
game.lv_easy_vostile_points=250;
game.lv_easy_vostile_speed_seed=5;
game.lv_easy_vostile_speed_adder=0;
game.lv_easy_num_targets=3;
game.lv_easy_target_points=100;
game.lv_easy_num_meanies=1;
game.lv_easy_has_entourage='NO';
game.lv_easy_num_followers=0;
game.lv_easy_num_valuables_bump=.2;	
game.lv_easy_valuable_speed_seed_bump=1;
game.lv_easy_valuable_speed_adder_bump=0;
game.lv_easy_num_hostiles_bump=.2;
game.lv_easy_hostile_speed_seed_bump=1;
game.lv_easy_hostile_speed_adder_bump=0;
game.lv_easy_num_vostiles_bump=.2;
game.lv_easy_vostile_speed_seed_bump=1;
game.lv_easy_vostile_speed_adder_bump=0;
game.lv_easy_num_targets_bump=.2;

game.lv_medium_num_valuables=4;
game.lv_medium_valuable_points=25;
game.lv_medium_valuable_speed_seed=3;
game.lv_medium_valuable_speed_adder=0;
game.lv_medium_num_hostiles=4;
game.lv_medium_hostile_points=250;
game.lv_medium_hostile_speed_seed=3;
game.lv_medium_hostile_speed_adder=1;
game.lv_medium_num_vostiles=4;
game.lv_medium_vostile_points=250;
game.lv_medium_vostile_speed_seed=8;
game.lv_medium_vostile_speed_adder=1;
game.lv_medium_num_targets=6;
game.lv_medium_target_points=100;
game.lv_medium_num_meanies=2;
game.lv_medium_has_entourage='YES';
game.lv_medium_num_followers=2;
game.lv_medium_num_valuables_bump=.3;	
game.lv_medium_valuable_speed_seed_bump=1;
game.lv_medium_valuable_speed_adder_bump=0;
game.lv_medium_num_hostiles_bump=.3;
game.lv_medium_hostile_speed_seed_bump=1;
game.lv_medium_hostile_speed_adder_bump=0;
game.lv_medium_num_vostiles_bump=.3;
game.lv_medium_vostile_speed_seed_bump=1;
game.lv_medium_vostile_speed_adder_bump=0;
game.lv_medium_num_targets_bump=.3;

game.lv_hard_num_valuables=6;
game.lv_hard_valuable_points=25;
game.lv_hard_valuable_speed_seed=4;
game.lv_hard_valuable_speed_adder=0;
game.lv_hard_num_hostiles=6;
game.lv_hard_hostile_points=250;
game.lv_hard_hostile_speed_seed=4;
game.lv_hard_hostile_speed_adder=1;
game.lv_hard_num_vostiles=6;
game.lv_hard_vostile_points=250;
game.lv_hard_vostile_speed_seed=11;
game.lv_hard_vostile_speed_adder=1;
game.lv_hard_num_targets=8;
game.lv_hard_target_points=100;
game.lv_hard_num_meanies=3;
game.lv_hard_has_entourage='YES';
game.lv_hard_num_followers=3;
game.lv_hard_num_valuables_bump=.51;	
game.lv_hard_valuable_speed_seed_bump=1;
game.lv_hard_valuable_speed_adder_bump=0;
game.lv_hard_num_hostiles_bump=.51;
game.lv_hard_hostile_speed_seed_bump=1;
game.lv_hard_hostile_speed_adder_bump=0;
game.lv_hard_num_vostiles_bump=.51;
game.lv_hard_vostile_speed_seed_bump=1;
game.lv_hard_vostile_speed_adder_bump=0;
game.lv_hard_num_targets_bump=.51;

//set based on json object.
if(fobj.ha) {game.score =parseInt(bdc(fobj.ha));}
if(fobj.hb) {game.level =parseInt(bdc(fobj.hb));}
if(fobj.hc) {game.game_levels =parseInt(bdc(fobj.hc));}
if(fobj.hd) {game.lives =parseInt(bdc(fobj.hd));}
if(fobj.he) {game.level_frames =parseInt(bdc(fobj.he));}
if(fobj.hf) {game.count_frames = parseInt(bdc(fobj.hf));}
if(fobj.hg) {game.life_bonus_num_points=parseInt(bdc(fobj.hg));}
if(fobj.hh) {game.life_next_bonus=parseInt(bdc(fobj.hh));}
if(fobj.hi) {game.on_fire_time=parseInt(bdc(fobj.hi));}

if(fobj.ia) {game.num_bullets = parseInt(bdc(fobj.ia));}
if(fobj.ib) {game.canshootvostile=bdc(fobj.ib);}
if(fobj.ic) {game.vostile_points=parseInt(bdc(fobj.ic));}
if(fobj.id) {game.canshoothostile=bdc(fobj.id);}
if(fobj.ie) {game.hostile_points=parseInt(bdc(fobj.ie));}
if(fobj.ifq) {game.canshootvaluables=bdc(fobj.ifq);}
if(fobj.ig) {game.valuable_points=parseInt(bdc(fobj.ig));}
if(fobj.ih) {game.sound_0=bdc(fobj.ih);}
if(fobj.ii) {game.sound_1=bdc(fobj.ii);}
if(fobj.ij) {game.easy_image=bdc(fobj.ij);}
if(fobj.ik) {game.medium_image=bdc(fobj.ik);}
if(fobj.il) {game.hard_image=bdc(fobj.il);}
if(fobj.im) {game.screen_width=parseInt(bdc(fobj.im));}
if(fobj.inq) {game.screen_height=parseInt(bdc(fobj.inq));}
if(fobj.io) {game.score_text=bdc(fobj.io);}
if(fobj.ip) {game.level_text=bdc(fobj.ip);}
if(fobj.iq) {game.lives_text=bdc(fobj.iq);}
if(fobj.ir) {game.frames_text=bdc(fobj.ir);}
if(fobj.is) {game.lost_life_text=bdc(fobj.is);}
if(fobj.it) {game.new_level_text=bdc(fobj.it);}
// length of interlude
if(fobj.iu) {game.lost_life_duration=parseInt(bdc(fobj.iu));}
if(fobj.iv) {game.new_level_duration=parseInt(bdc(fobj.iv));}
if(fobj.iw) {game.hero_start_x=parseInt(bdc(fobj.iw));}
if(fobj.ix) {game.hero_start_y=parseInt(bdc(fobj.ix));}
if(fobj.iy) {game.hero_x_limit_left=parseInt(bdc(fobj.iy));}
if(fobj.iz) {game.hero_x_limit_right=parseInt(bdc(fobj.iz));}
if(fobj.ja) {game.hero_y_limit_top=parseInt(bdc(fobj.ja));}
if(fobj.jb) {game.hero_y_limit_bottom=parseInt(bdc(fobj.jb));}
if(fobj.jc) {game.targets_x_limit_left=parseInt(bdc(fobj.jc));}
if(fobj.jd) {game.targets_x_limit_right=parseInt(bdc(fobj.jd));}
if(fobj.je) {game.targets_y_limit_top=parseInt(bdc(fobj.je));}
if(fobj.jf) {game.targets_y_limit_bottom=parseInt(bdc(fobj.jf));}
if(fobj.jg) {game.helper_start_x=parseInt(bdc(fobj.jg));}
if(fobj.jh) {game.helper_start_y=parseInt(bdc(fobj.jh));}
if(fobj.ji) {game.follower_distance=parseInt(bdc(fobj.ji));}
if(fobj.jj) {game.follower_trail_array_size=parseInt(bdc(fobj.jj));}

if(fobj.ka) {game.lv_easy_num_valuables=parseInt(bdc(fobj.ka));}
if(fobj.kb) {game.lv_easy_valuable_points=parseInt(bdc(fobj.kb));}
if(fobj.kc) {game.lv_easy_valuable_speed_seed=parseInt(bdc(fobj.kc));}
if(fobj.kd) {game.lv_easy_valuable_speed_adder=parseInt(bdc(fobj.kd));}
if(fobj.ke) {game.lv_easy_num_hostiles=parseInt(bdc(fobj.ke));}
if(fobj.kf) {game.lv_easy_hostile_points=parseInt(bdc(fobj.kf));}
if(fobj.kg) {game.lv_easy_hostile_speed_seed=parseInt(bdc(fobj.kg));}
if(fobj.kh) {game.lv_easy_hostile_speed_adder=parseInt(bdc(fobj.kh));}
if(fobj.ki) {game.lv_easy_num_vostiles=parseInt(bdc(fobj.ki));}
if(fobj.kj) {game.lv_easy_vostile_points=parseInt(bdc(fobj.kj));}
if(fobj.kk) {game.lv_easy_vostile_speed_seed=parseInt(bdc(fobj.kk));}
if(fobj.kl) {game.lv_easy_vostile_speed_adder=parseInt(bdc(fobj.kl));}
if(fobj.km) {game.lv_easy_num_targets=parseInt(bdc(fobj.km));}
if(fobj.kn) {game.lv_easy_target_points=parseInt(bdc(fobj.kn));}
if(fobj.ko) {game.lv_easy_num_meanies=parseInt(bdc(fobj.ko));}
if(fobj.kp) {game.lv_easy_has_entourage=bdc(fobj.kp);}
if(fobj.kq) {game.lv_easy_num_followers=parseInt(bdc(fobj.kq));}
if(fobj.kr) {game.lv_easy_num_valuables_bump=parseFloat(bdc(fobj.kr));}
if(fobj.ks) {game.lv_easy_valuable_speed_seed_bump=parseInt(bdc(fobj.ks));}
if(fobj.kt) {game.lv_easy_valuable_speed_adder_bump=parseInt(bdc(fobj.kt));}
if(fobj.ku) {game.lv_easy_num_hostiles_bump=parseFloat(bdc(fobj.ku));}
if(fobj.kv) {game.lv_easy_hostile_speed_seed_bump=parseInt(bdc(fobj.kv));}
if(fobj.kw) {game.lv_easy_hostile_speed_adder_bump=parseInt(bdc(fobj.kw));}
if(fobj.kx) {game.lv_easy_num_vostiles_bump=parseFloat(bdc(fobj.kx));}
if(fobj.ky) {game.lv_easy_vostile_speed_seed_bump=parseInt(bdc(fobj.ky));}
if(fobj.kz) {game.lv_easy_vostile_speed_adder_bump=parseInt(bdc(fobj.kz));}
if(fobj.kzz) {game.lv_easy_num_targets_bump=parseFloat(bdc(fobj.kzz));}

if(fobj.mka) {game.lv_medium_num_valuables=parseInt(bdc(fobj.mka));}
if(fobj.mkb) {game.lv_medium_valuable_points=parseInt(bdc(fobj.mkb));}
if(fobj.mkc) {game.lv_medium_valuable_speed_seed=parseInt(bdc(fobj.mkc));}
if(fobj.mkd) {game.lv_medium_valuable_speed_adder=parseInt(bdc(fobj.mkd));}
if(fobj.mke) {game.lv_medium_num_hostiles=parseInt(bdc(fobj.mke));}
if(fobj.mkf) {game.lv_medium_hostile_points=parseInt(bdc(fobj.mkf));}
if(fobj.mkg) {game.lv_medium_hostile_speed_seed=parseInt(bdc(fobj.mkg));}
if(fobj.mkh) {game.lv_medium_hostile_speed_adder=parseInt(bdc(fobj.mkh));}
if(fobj.mki) {game.lv_medium_num_vostiles=parseInt(bdc(fobj.mki));}
if(fobj.mkj) {game.lv_medium_vostile_points=parseInt(bdc(fobj.mkj));}
if(fobj.mkk) {game.lv_medium_vostile_speed_seed=parseInt(bdc(fobj.mkk));}
if(fobj.mkl) {game.lv_medium_vostile_speed_adder=parseInt(bdc(fobj.mkl));}
if(fobj.mkm) {game.lv_medium_num_targets=parseInt(bdc(fobj.mkm));}
if(fobj.mkn) {game.lv_medium_target_points=parseInt(bdc(fobj.mkn));}
if(fobj.mko) {game.lv_medium_num_meanies=parseInt(bdc(fobj.mko));}
if(fobj.mkp) {game.lv_medium_has_entourage=bdc(fobj.mkp);}
if(fobj.mkq) {game.lv_medium_num_followers=parseInt(bdc(fobj.mkq));}
if(fobj.mkr) {game.lv_medium_num_valuables_bump=parseFloat(bdc(fobj.mkr));}
if(fobj.mks) {game.lv_medium_valuable_speed_seed_bump=parseInt(bdc(fobj.mks));}
if(fobj.mkt) {game.lv_medium_valuable_speed_adder_bump=parseInt(bdc(fobj.mkt));}
if(fobj.mku) {game.lv_medium_num_hostiles_bump=parseFloat(bdc(fobj.mku));}
if(fobj.mkv) {game.lv_medium_hostile_speed_seed_bump=parseInt(bdc(fobj.mkv));}
if(fobj.mkw) {game.lv_medium_hostile_speed_adder_bump=parseInt(bdc(fobj.mkw));}
if(fobj.mkx) {game.lv_medium_num_vostiles_bump=parseFloat(bdc(fobj.mkx));}
if(fobj.mky) {game.lv_medium_vostile_speed_seed_bump=parseInt(bdc(fobj.mky));}
if(fobj.mkz) {game.lv_medium_vostile_speed_adder_bump=parseInt(bdc(fobj.mkz));}
if(fobj.mkzz) {game.lv_medium_num_targets_bump=parseFloat(bdc(fobj.mkzz));}

if(fobj.hka) {game.lv_hard_num_valuables=parseInt(bdc(fobj.hka));}
if(fobj.hkb) {game.lv_hard_valuable_points=parseInt(bdc(fobj.hkb));}
if(fobj.hkc) {game.lv_hard_valuable_speed_seed=parseInt(bdc(fobj.hkc));}
if(fobj.hkd) {game.lv_hard_valuable_speed_adder=parseInt(bdc(fobj.hkd));}
if(fobj.hke) {game.lv_hard_num_hostiles=parseInt(bdc(fobj.hke));}
if(fobj.hkf) {game.lv_hard_hostile_points=parseInt(bdc(fobj.hkf));}
if(fobj.hkg) {game.lv_hard_hostile_speed_seed=parseInt(bdc(fobj.hkg));}
if(fobj.hkh) {game.lv_hard_hostile_speed_adder=parseInt(bdc(fobj.hkh));}
if(fobj.hki) {game.lv_hard_num_vostiles=parseInt(bdc(fobj.hki));}
if(fobj.hkj) {game.lv_hard_vostile_points=parseInt(bdc(fobj.hkj));}
if(fobj.hkk) {game.lv_hard_vostile_speed_seed=parseInt(bdc(fobj.hkk));}
if(fobj.hkl) {game.lv_hard_vostile_speed_adder=parseInt(bdc(fobj.hkl));}
if(fobj.hkm) {game.lv_hard_num_targets=parseInt(bdc(fobj.hkm));}
if(fobj.hkn) {game.lv_hard_target_points=parseInt(bdc(fobj.hkn));}
if(fobj.hko) {game.lv_hard_num_meanies=parseInt(bdc(fobj.hko));}
if(fobj.hkp) {game.lv_hard_has_entourage=bdc(fobj.hkp);}
if(fobj.hkq) {game.lv_hard_num_followers=parseInt(bdc(fobj.hkq));}
if(fobj.hkr) {game.lv_hard_num_valuables_bump=parseFloat(bdc(fobj.hkr));}
if(fobj.hks) {game.lv_hard_valuable_speed_seed_bump=parseInt(bdc(fobj.hks));}
if(fobj.hkt) {game.lv_hard_valuable_speed_adder_bump=parseInt(bdc(fobj.hkt));}
if(fobj.hku) {game.lv_hard_num_hostiles_bump=parseFloat(bdc(fobj.hku));}
if(fobj.hkv) {game.lv_hard_hostile_speed_seed_bump=parseInt(bdc(fobj.hkv));}
if(fobj.hkw) {game.lv_hard_hostile_speed_adder_bump=parseInt(bdc(fobj.hkw));}
if(fobj.hkx) {game.lv_hard_num_vostiles_bump=parseFloat(bdc(fobj.hkx));}
if(fobj.hky) {game.lv_hard_vostile_speed_seed_bump=parseInt(bdc(fobj.hky));}
if(fobj.hkz) {game.lv_hard_vostile_speed_adder_bump=parseInt(bdc(fobj.hkz));}
if(fobj.hkzz) {game.lv_hard_num_targets_bump=parseFloat(bdc(fobj.hkzz));}

origlives=game.lives; 

var compdate=bdc(fobj.daa);

  var today = new Date();
  var year = today.getYear();
  if (year < 2000) {
    year = year + 1900;
  }
  var month = today.getMonth() + 6;
  var premonth='';
  if (month <= 9) {
    premonth='0';
  }
  var day = today.getDate();
  var preday='';
  if (day <= 9) {
    preday='0';
  }
  var thisdate=year +premonth+month+preday+day;
  //alert('compdate: ' + compdate + ' thidate: ' + thisdate);

//if (compdate > thisdate) {


	//set first level of difficulty
	level_set_0();
	level_set_1();
	level_set_2();
	gtypeoverrides();
				
	myEasy=new In_Button(
		10,					// x
		250,					// y
		60,					// width
		20,					// height
		"image",				// type of button
		"start_init('easy')",	// statement to be executed when button clicked
		game.easy_image,	// button initial image
		game.easy_image,	// button mouse out image (usually same as above)
		game.easy_image,	// button mouse over image
		game.easy_image	// button mouse click image
	);

	myMedium=new In_Button(
		10,					// x
		300,					// y
		60,					// width
		20,					// height
		"image",				// type of button
		"start_init('medium')",	// statement to be executed when button clicked
		game.medium_image,	// button initial image
		game.medium_image,	// button mouse out image (usually same as above)
		game.medium_image,	// button mouse over image
		game.medium_image	// button mouse click image
	);
	
	myHard=new In_Button(
		10,					// x
		350,					// y
		60,					// width
		20,					// height
		"image",				// type of button
		"start_init('hard')",	// statement to be executed when button clicked
		game.hard_image,	// button initial image
		game.hard_image,	// button mouse out image (usually same as above)
		game.hard_image,	// button mouse over image
		game.hard_image	// button mouse click image
	);	
	
	mymouse=Ms_initmouse();			// start the mouse handler...	
	
	var mysiteTextall='<span class="styleInfo"><iframe height="45" width="200" frameborder="0" scrolling="no" src="http://www.postikit.com/badge.html></iframe></span>';
	mysiteText=new Gl_layer(500,0,200,mysiteTextall);
	
	var websiteTextall='<span class="styleInfo">' + game.def002 + '</span>';
	websiteText=new Gl_layer(175,25,400,websiteTextall);
	
	var titleTextall='<span class="styleInfo">' + game.abc001 + '</span>';
	titleText=new Gl_layer(175,5,400,titleTextall);
	
	var scoreTextall='<span class="styleInfo">' + game.score_text + '</span>';
	scoreText=new Gl_layer(10,5,300,scoreTextall);	

	var scoreTextallz='<span class="styleInfo" style="color:white;">' + game.score + '</span>';
	scoreTextz=new Gl_layer(10,30,300,scoreTextallz);
		
	var levelTextall='<span class="styleInfo">' + game.level_text + '</span>';
	levelText=new Gl_layer(10,55,300,levelTextall);	

	var levelTextallz='<span class="styleInfo" style="color:white;">' + game.level + '</span>';
	levelTextz=new Gl_layer(10,75,300,levelTextallz);
	
	var livesTextall='<span class="styleInfo">' + game.lives_text + '</span>';
	livesText=new Gl_layer(10,105,300,livesTextall);	

	var livesTextallz='<span class="styleInfo" style="color:white;">' + game.lives + '</span>';
	livesTextz=new Gl_layer(10,131,300,livesTextallz);
			
	var framesTextall='<span class="styleInfo">' + game.frames_text + '</span>';
	framesText=new Gl_layer(10,155,300,framesTextall);	

	var framesTextallz='<span class="styleInfo" style="color:white;">' + game.count_frames + '</span>';
	framesTextz=new Gl_layer(10,180,300,framesTextallz);
		
	var lost_lifeTextall='<span class="styleInfo">' + game.lost_life_text + '</span>';
	mylifelostlayer=new Gl_layer(300,300,100,lost_lifeTextall);
	mylifelostlayer.hide();
	
	var new_levelTextall='<span class="styleInfo">' + game.new_level_text + '</span>';
	mynewlevellayer=new Gl_layer(300,200,300,new_levelTextall);
	mynewlevellayer.hide();


// gets directory game is in.
var myloc = window.location.href;
//alert('myloc: ' + myloc);
var locarray = myloc.split("/");
//alert('locarray: ' + locarray);
var thedir=locarray[(locarray.length-1)];
if (thedir == '') {
	thedir=locarray[(locarray.length-2)];
}
thedir='/' + thedir;
//alert('thedir: ' + thedir);

	//myInterface=new In_Interface(500,500,thedir);
	myInterface=new In_Interface(500,500,'/gamelibsf');	

	//scoreDigits=new In_NumericDisplay(10,28,6,0);
	//levelDigits=new In_NumericDisplay(10,80,3,0);
	//livesDigits=new In_NumericDisplay(10,130,3,0);
	//framesDigits=new In_NumericDisplay(10,180,3,0);
	//myInterface.add(scoreDigits);
	//myInterface.add(levelDigits);
	//myInterface.add(livesDigits);
	//myInterface.add(framesDigits);
	myInterface.moveTo(0,0);	
	myInterface.add(myEasy);
	myInterface.add(myMedium);
	myInterface.add(myHard);

	myInterface.show();			// and show it (it's actually shown by default, so this is not necessary)
					
	Gl_scrollbars("no");	// turn off scroll-bars (with IE)	
	
	//hard sprite
	//wall=new Sp_Sprite();
	//wall.setImage('images/bullet_____016_016_blueorange.png',16,16,1,1); 
	//wall.setXlimits(100,game.screen_width+100);	
	//wall.setYlimits(50,game.screen_height+50);
	//wall.setFrame(0);		
	//wall.setAnimationLoop(0,1);	
	//wall.setAnimationSpeed(2,"forward"); 
	//wall.setAnimation(0);
	//wall.setAnimationRepeat(-1);	
	//wall.moveTo(100,1);
	//wall.collides=true;
	//wall.useHitEvents(true);
	//wall.hard=true;
	//wall.switchOn();
	directions_on();
	
//} else {
   //alert('This game has expired.  Visit advergames.web-skillset.com!');
 //}
};

function start_init(in_difficulty){
	//set first level of difficulty
    //alert('in start init');  

	
	 	in_levels_interlude = 'yes';
		in_levels_interlude_ctr = 0;	
		game_difficulty=in_difficulty;
    	game.score=0;
    	game.level=1;
    	game.lives=origlives;
    	show_score();
    	game.count_frames = 0; 
    
    	//set difficutly
		if (game_difficulty == 'easy') {
			q=0;
		}	
		if (game_difficulty == 'medium') {
			q=1;	
		}
		if (game_difficulty == 'hard') {
			q=2;
		}
    
	if (started =='no') {

		started='yes';



		// create multi dimension array for entourage.
		for(f=0;f<lv[q].num_followers;f++){	
		    //alert('creating entourage f: ' +f);
			game.entourage[f]=new Array;
		}
		
		

		if (game.gtype == 'Classic') {
			hero_init();
			helper_init();
			hero_start();
			helper_start();
			valuables_start();
			hostiles_start();
			vostiles_start();		
			targets_start();	
			meanies_start();
			bullets_start();
	
	        if (hookonce == 'no') {
				Gl_hook("level_bump(game_difficulty)");
				Gl_hook("levels_interlude()");
				Gl_hook("lives_interlude()");		
				Gl_hook("hero_animate()");
				Gl_hook("helper_animate()");
				Gl_hook("helper_deflect()");
				Gl_hook("valuables_animate()");	
				Gl_hook("bullets_animate()");
				Gl_hook("bullets_deflect()");
				Gl_hook("hostiles_animate()");
				Gl_hook("vostiles_animate()");
				Gl_hook("targets_animate()");	
				Gl_hook("meanies_animate()");
				Gl_hook("meanies_hit()");
				hookonce='yes';
			}
		}		
		
		if (game.gtype == 'Catching Things') {
			hero_init();
			//helper_init();
			hero_start();
			//helper_start();
			valuables_start();
			hostiles_start();
			vostiles_start();		
			//targets_start();	
			//meanies_start();
			//bullets_start();
	
		    if (hookonce == 'no') {
				Gl_hook("level_bump(game_difficulty)");
				Gl_hook("levels_interlude()");
				Gl_hook("lives_interlude()");		
				Gl_hook("hero_animate()");
				//Gl_hook("helper_animate()");
				//Gl_hook("helper_deflect()");
				Gl_hook("valuables_animate()");	
				//Gl_hook("bullets_animate()");
				//Gl_hook("bullets_deflect()");
				Gl_hook("hostiles_animate()");
				Gl_hook("vostiles_animate()");
				Gl_hook("vostiles_deflect()");
				//Gl_hook("targets_animate()");	
				//Gl_hook("meanies_animate()");
				//Gl_hook("meanies_hit()");
				hookonce='yes';
			}
		}			
		
		if (game.gtype == 'Shooting Gallery') {
			hero_init();
			//helper_init();
			hero_start();
			//helper_start();
			valuables_start();
			hostiles_start();
			vostiles_start();		
			//targets_start();	
			//meanies_start();
			bullets_start();
			
			if (hookonce == 'no') {
				Gl_hook("level_bump(game_difficulty)");
				Gl_hook("levels_interlude()");
				Gl_hook("lives_interlude()");		
				Gl_hook("hero_animate()");
				//Gl_hook("helper_animate()");
				//Gl_hook("helper_deflect()");
				Gl_hook("valuables_animate()");	
				Gl_hook("bullets_animate()");
				Gl_hook("bullets_deflect()");
				Gl_hook("hostiles_animate()");
				Gl_hook("vostiles_animate()");
				//Gl_hook("targets_animate()");	
				//Gl_hook("meanies_animate()");
				//Gl_hook("meanies_hit()");
				hookonce='yes';
			}
		}
		if (game.gtype == 'Shooting Ball') {
			hero_init();
			helper_init();
			hero_start();
			helper_start();
			//valuables_start();
			hostiles_start();
			//vostiles_start();		
			//targets_start();	
			//meanies_start();
			bullets_start();
			
			if (hookonce == 'no') {
				Gl_hook("level_bump(game_difficulty)");
				Gl_hook("levels_interlude()");
				Gl_hook("lives_interlude()");		
				Gl_hook("hero_animate()");
				Gl_hook("helper_animate()");
				Gl_hook("helper_deflect()");
				//Gl_hook("valuables_animate()");	
				Gl_hook("bullets_animate()");
				Gl_hook("bullets_deflect()");
				Gl_hook("hostiles_animate()");
				//Gl_hook("vostiles_animate()");
				//Gl_hook("targets_animate()");	
				//Gl_hook("meanies_animate()");
				//Gl_hook("meanies_hit()");
				hookonce='yes';
			}
		}
		if (game.gtype == 'Bomb Drop') {
			hero_init();
			//helper_init();
			hero_start();
			//helper_start();
			valuables_start();
			hostiles_start();
			vostiles_start();		
			//targets_start();	
			//meanies_start();
			bullets_start();
	
			
			if (hookonce == 'no') {	
				Gl_hook("level_bump(game_difficulty)");
				Gl_hook("levels_interlude()");
				Gl_hook("lives_interlude()");		
				Gl_hook("hero_animate()");
				//Gl_hook("helper_animate()");
				//Gl_hook("helper_deflect()");
				Gl_hook("valuables_animate()");	
				Gl_hook("bullets_animate()");
				Gl_hook("bullets_deflect()");
				Gl_hook("hostiles_animate()");
				Gl_hook("vostiles_animate()");
				//Gl_hook("targets_animate()");	
				//Gl_hook("meanies_animate()");
				//Gl_hook("meanies_hit()");
				hookonce='yes';
			}
		}		
		
		
		Gl_start();			// start everything moving!
	}
	directions_off();
};

function levels_interlude(){
	if (in_levels_interlude == 'yes') {
		in_levels_interlude_ctr=in_levels_interlude_ctr + 1;
		
		switch(game.gtype) {
			case 'Shooting Gallery':
				valuables_end();
				hostiles_end();
				vostiles_end();		
				//meanies_end();
			break;
			case 'Shooting Ball':
				//valuables_end();
				hostiles_end();
				//vostiles_end();		
				//meanies_end();
			break;
			case 'Bomb Drop':
				valuables_end();
				hostiles_end();
				vostiles_end();		
				//meanies_end();
			break;
			case 'Catching Things':
				valuables_end();
				hostiles_end();
				vostiles_end();		
				//meanies_end();
			break;		
			default:
				valuables_end();
				hostiles_end();
				vostiles_end();		
				meanies_end();
			break;
		}
		
		if (in_levels_interlude_ctr==1) {
			new_levelTextall='<span class="styleInterlude">' + game.new_level_text + '<br>' + game.ghi003[game.level] + '</span>';
			mynewlevellayer=new Gl_layer(200,200,300,new_levelTextall);
			mynewlevellayer.show();
		}
		if(in_levels_interlude_ctr >game.new_level_duration) {
			in_levels_interlude = 'no';
			in_levels_interlude_ctr=0;
 			mynewlevellayer.hide(); 
			switch(game.gtype) {
				case 'Shooting Gallery':
					valuables_start();
					hostiles_start();
					vostiles_start();		
					//meanies_start();
				break;
				case 'Shooting Ball':
					//valuables_start();
					hostiles_start();
					//vostiles_start();		
					//meanies_start();
				break;
				case 'Bomb Drop':
					valuables_start();
					hostiles_start();
					vostiles_start();		
					//meanies_start();
				break;
				case 'Catching Things':
					valuables_start();
					hostiles_start();
					vostiles_start();		
					//meanies_start();
				break;		
				default:
					valuables_start();
					hostiles_start();
					vostiles_start();		
					meanies_start();
				break;
			}
		}
	}	
};

function lives_interlude(){
	if (in_lives_interlude == 'yes') {
		in_lives_interlude_ctr=in_lives_interlude_ctr + 1;
		switch(game.gtype) {
			case 'Shooting Gallery':
				valuables_end();
				hostiles_end();
				vostiles_end();		
				//meanies_end();
			break;
			case 'Shooting Ball':
				//valuables_end();
				hostiles_end();
				//vostiles_end();		
				//meanies_end();
			break;
			case 'Bomb Drop':
				valuables_end();
				hostiles_end();
				vostiles_end();		
				//meanies_end();
			break;
			case 'Catching Things':
				valuables_end();
				hostiles_end();
				vostiles_end();		
				//meanies_end();
			break;		
			default:
				valuables_end();
				hostiles_end();
				vostiles_end();		
				meanies_end();
			break;
		}
		if (in_lives_interlude_ctr==1) {
			mylifelostlayer.show();
		}
		if(in_lives_interlude_ctr >game.lost_life_duration) {
			in_lives_interlude = 'no';
			in_lives_interlude_ctr=0;
 			mylifelostlayer.hide(); 
			switch(game.gtype) {
				case 'Shooting Gallery':
					valuables_start();
					hostiles_start();
					vostiles_start();		
					//meanies_start();
				break;
				case 'Shooting Ball':
					//valuables_start();
					hostiles_start();
					//vostiles_start();		
					//meanies_start();
				break;
				case 'Bomb Drop':
					valuables_start();
					hostiles_start();
					vostiles_start();		
					//meanies_start();
				break;
				case 'Catching Things':
					valuables_start();
					hostiles_start();
					vostiles_start();		
					//meanies_start();
				break;		
				default:
					valuables_start();
					hostiles_start();
					vostiles_start();		
					meanies_start();
				break;
			}
		}
	}	
};

function life_loss(){
	life_loss_counter=life_loss_counter+1;
	if(life_loss_counter >=life_loss_num_fires) {
		game.lives=game.lives-1;
		in_lives_interlude='yes';
		life_loss_counter=0;
	}
	//reset if numb lives is 0
	if(game.lives <=0) {
	    end_everything();
	 	game.lives=origlives;
	 	game.count_frames = 0;
		started='no';
	}
};

function end_everything () {
				switch(game.gtype) {
					case 'Shooting Gallery':
						hero_end();
						//helper_end();
						valuables_end();
						hostiles_end();
						vostiles_end();
						//targets_end();
						//meanies_end();
					break;
					case 'Shooting Ball':
						hero_end();
						helper_end();
						//valuables_end();
						hostiles_end();
						//vostiles_end();
						//targets_end();
						//meanies_end();
					break;
					case 'Bomb Drop':
						hero_end();
						//helper_end();
						valuables_end();
						hostiles_end();
						vostiles_end();
						//targets_end();
						//meanies_end();
					break;
					case 'Catching Things':
						hero_end();
						//helper_end();
						valuables_end();
						hostiles_end();
						vostiles_end();
						//targets_end();
						//meanies_end();
					break;		
					default:
						hero_end();
						helper_end();
						valuables_end();
						hostiles_end();
						vostiles_end();
						targets_end();
						meanies_end();
					break;
				} 
 }

function level_bump(game_difficulty){
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){
		if ((game.level <= game.game_levels) && (game.lives > 0)) {
		
			game.count_frames=game.count_frames + 1;
			var framesz='<span class="styleInfo" style="color:white;">' + game.count_frames + '</span>';
			framesTextz.write(framesz);	
			//framesDigits.setValue(game.count_frames);
			if (game.count_frames >= game.level_frames) {
	
			    end_everything();

							
					
				if (game_difficulty == 'easy') {
					level_bump_0();
				}	
				if (game_difficulty == 'medium') {
					level_bump_1();	
				}
				if (game_difficulty == 'hard') {
					level_bump_2();	
				}
		     	//reset game.count_frames
				game.count_frames=0;	
				game.level=game.level+1;
				
				var levelz='<span class="styleInfo" style="color:white;">' + game.level + '</span>';
				levelTextz.write(levelz);
				//levelDigits.setValue(game.level);
				in_levels_interlude='yes';
				in_levels_interlude_ctr=0;
			
				switch(game.gtype) {
					case 'Shooting Gallery':
						hero_start();
						//helper_start();
						valuables_start();
						hostiles_start();
						vostiles_start();
						//targets_start();
						//meanies_start();
					break;
					case 'Shooting Ball':
						hero_start();
						helper_start();
						//valuables_start();
						hostiles_start();
						//vostiles_start();
						//targets_start();
						//meanies_start();
					break;
					case 'Bomb Drop':
						hero_start();
						//helper_start();
						valuables_start();
						hostiles_start();
						vostiles_start();
						//targets_start();
						//meanies_start();
					break;
					case 'Catching Things':
						hero_start();
						//helper_start();
						valuables_start();
						hostiles_start();
						vostiles_start();
						//targets_start();
						//meanies_start();
					break;		
					default:
						hero_start();
						helper_start();
						valuables_start();
						hostiles_start();
						vostiles_start();
						targets_start();
						meanies_start();
					break;
				}			
			}
		} else {
			//end game
				end_everything();
			
		}
	}	
};

function sprite_moveto(insprite,inwhat) {
	var rand=0;
	var xmin=100;
	var xmax=game.screen_width+100;
	var ymin=50;
	var ymax=game.screen_height+50;
	var yrange=ymax-ymin;
	var xrange=xmax-xmin;
	var hold_hostile_dir= game.hostile_dir;
	
	// this is starting placement of  valuables
	if (inwhat == 'valuable') {
		rand=Math.random();
		switch(game.valuable_dir){
			// x between 50 - 550  
			// y between 50 - 150  
			case 'top to bottom':
				insprite.moveTo( ((rand*xrange)+xmin) , ((rand*50)+ymin) );	
			break;
			
			// x between 50 - 550 
			// y between 450 - 550	
			case 'bottom to top':
				insprite.moveTo( ((rand*xrange)+xmin) , (ymax-(rand*50)) );
			break;
			
			// x between 450 - 550  
			// y between 50 - 550			
			case 'right to left':
				insprite.moveTo( (xmax-(rand*100)) , ((rand*yrange)+ymin) );		
			break;
			
			// x between 50 - 150  
			// y between 50 - 550			
			case 'left to right':
				insprite.moveTo( ((rand*100)+xmin) , ((rand*yrange)+ymin));
			break;		
		}
	}
	// this is starting placement of hostiles 
	if (inwhat == 'hostile') {
		rand=Math.random();
		switch(game.hostile_dir){
			// x between 50 - 550  
			// y between 50 - 150  
			case 'top to bottom':
				insprite.moveTo( ((rand*xrange)+xmin) , ((rand*50)+ymin) );	
			break;
			
			// x between 50 - 550 
			// y between 450 - 550	
			case 'bottom to top':
				insprite.moveTo( ((rand*xrange)+xmin) , (ymax-(rand*50)) );
			break;
			
			// x between 450 - 550  
			// y between 50 - 550			
			case 'right to left':
				insprite.moveTo( (xmax-(rand*100)) , ((rand*yrange)+ymin) );		
			break;
			
			// x between 50 - 150  
			// y between 50 - 550			
			case 'left to right':
			    if (game.gtype=='Shooting Ball') {
				insprite.moveTo( ((rand*100)+0) , ((rand*yrange)+ymin));
				} else { 
				insprite.moveTo( ((rand*100)+xmin) , ((rand*yrange)+ymin));
				}
			break;		
		}
	}
	// this is starting placement of vostiles 
	if (inwhat == 'vostile') {
		rand=Math.random();
		switch(game.vostile_dir){
			// x between 50 - 550  
			// y between 50 - 150  
			case 'top to bottom':
				insprite.moveTo( ((rand*xrange)+xmin) , ((rand*50)+ymin) );	
			break;
			
			// x between 50 - 550 
			// y between 450 - 550	
			case 'bottom to top':
				insprite.moveTo( ((rand*xrange)+xmin) , (ymax-(rand*50)) );
			break;
			
			// x between 450 - 550  
			// y between 50 - 550			
			case 'right to left':
				insprite.moveTo( (xmax-(rand*100)) , ((rand*yrange)+ymin) );		
			break;
			
			// x between 50 - 150  
			// y between 50 - 550			
			case 'left to right':
				insprite.moveTo( ((rand*100)+xmin) , ((rand*yrange)+ymin));
			break;		
		}
	}
	// this is starting placement of targets, on opposite end of screen from 
	// target
	var trand=0;
	var txmin=game.targets_x_limit_left;
	var txmax=game.targets_x_limit_right;
	var tymin=game.targets_y_limit_top;
	var tymax=game.targets_y_limit_bottom;
	var tyrange=tymax-tymin;
	var txrange=txmax-txmin;
	if (inwhat == 'target') {
		trand=Math.random();
		switch(game.hostile_dir){
			// x between 50 - 550  
			// y between 450 - 550  
			case 'top to bottom':
				insprite.moveTo( ((trand*txrange)+txmin) , (tymax-(trand*50)) );	
			break;
			
			// x between 50 - 550 
			// y between 50 - 150	
			case 'bottom to top':
				insprite.moveTo( ((trand*txrange)+txmin) , ((trand*50)+tymin) );
			break;
			
			// x between 50 - 150  
			// y between 50 - 550			
			case 'right to left':
				insprite.moveTo( ((trand*100)+txmin) , ((trand*tyrange)+tymin) );		
			break;
			
			// x between 450 - 550  
			// y between 50 - 550			
			case 'left to right':
				insprite.moveTo( (txmax-(trand*100)) , ((trand*tyrange)+tymin));
			break;		
		}
	}	
	// this is starting placement of helper, on opposite end of screen from 
	// helper
	if (inwhat == 'helper') {
	 	var tyrange=20;
	    var txrange=20;
		trand=Math.random();
		if (game.gtype == 'Shooting Ball') {
			game.hostile_dir='top to bottom';
		} 
		switch(game.hostile_dir){
			// x between 50 - 550  
			// y between 450 - 550  
			case 'top to bottom':
				if (game.gtype == 'Shooting Ball') {
					insprite.moveTo( ((trand*txrange)+txmin) , (tymax-(trand*50)+25) );
				} else { 
					insprite.moveTo( ((trand*txrange)+txmin) , (tymax-(trand*50)) );	
				}
			break;
			// x between 50 - 550 
			// y between 50 - 150	
			case 'bottom to top':
				insprite.moveTo( ((trand*txrange)+txmin) , ((rand*50)+tymin) );
			break;
			// x between 50 - 150  
			// y between 50 - 550			
			case 'right to left':
				insprite.moveTo( ((trand*100)+txmin) , (t(rand*tyrange)+tymin) );		
			break;
			// x between 450 - 550  
			// y between 50 - 550			
			case 'left to right':
				insprite.moveTo( (txmax-(trand*100)) , ((trand*tyrange)+tymin));
			break;		
		}
		if (game.gtype == 'Shooting Ball') {
			game.hostile_dir=hold_hostile_dir;
		} 
	}
	
};


function sprite_setdir(insprite,inwhat) {

    //bullets opposite hostiles 
	if (inwhat == 'bullet') {
	 	switch(game.gtype) {
		case 'Shooting Gallery':
			insprite.setDir(0,-1);
			break;
		case 'Shooting Ball':
			insprite.setDir(0,-1);
			break;
		case 'Bomb Drop':
			insprite.setDir(0,1);
			break;
		default:
			if (game.hostile_dir == 'top to bottom') {
				insprite.setDir(0,-1);
			}
			if (game.hostile_dir == 'bottom to top') {
				insprite.setDir(0,1);
			}
			if (game.hostile_dir == 'right to left') {
				insprite.setDir(1,0);
			}
			if (game.hostile_dir == 'left to right') {
				insprite.setDir(-1,0);
			}
		}
	}
	if (inwhat == 'hostile') {	
		if (game.hostile_dir == 'top to bottom') {
			insprite.setDir(0,1);
		}
		if (game.hostile_dir == 'bottom to top') {
			insprite.setDir(0,-1);
		}
		if (game.hostile_dir == 'right to left') {
			insprite.setDir(-1,0);
		}
		if (game.hostile_dir == 'left to right') {
			insprite.setDir(1,0);
		}	
	}
	if (inwhat == 'vostile') {
	 	switch(game.gtype) {
		case 'Bomb Drop':
			insprite.setDir(0,-1);
			break;
		default:
			if (game.vostile_dir == 'top to bottom') {
				insprite.setDir(0,1);
			}
			if (game.vostile_dir == 'bottom to top') {
				insprite.setDir(0,-1);
			}
			if (game.vostile_dir == 'right to left') {
				insprite.setDir(-1,0);
			}
			if (game.vostile_dir == 'left to right') {
				insprite.setDir(1,0);
			}
		}
	}
	if (inwhat == 'valuable') {	
		if (game.valuable_dir == 'top to bottom') {
			insprite.setDir(0,1);
		}
		if (game.valuable_dir == 'bottom to top') {
			insprite.setDir(0,-1);
		}
		if (game.valuable_dir == 'right to left') {
			insprite.setDir(-1,0);
		}
		if (game.valuable_dir == 'left to right') {
			insprite.setDir(1,0);
		}	
	}
	if (inwhat == 'helper') {	
		if (game.hostile_dir == 'top to bottom') {
			insprite.setDir(1,0);
		}
		if (game.hostile_dir == 'bottom to top') {
			insprite.setDir(1,0);
		}
		if (game.hostile_dir == 'right to left') {
			insprite.setDir(0,1);
		}
		if (game.hostile_dir == 'left to right') {
			insprite.setDir(0,1);
		}	
	}	
};


function show_score(){
	// give life bonuses
	if (game.score > game.life_next_bonus) {
		game.lives=game.lives+1;
		game.life_next_bonus=game.life_next_bonus+game.life_bonus_num_points;
	}
	
	var scorez='<span class="styleInfo"  style="color:white;">' + game.score + '</span>';
	scoreTextz.write(scorez);	
	//scoreDigits.setValue(game.score);
	
	var levelz='<span class="styleInfo" style="color:white;">' + game.level + '</span>';
	levelTextz.write(levelz);
	//levelDigits.setValue(game.level);
	
	var livesz='<span class="styleInfo" style="color:white;">' + game.lives + '</span>';
	livesTextz.write(livesz);	
	//livesDigits.setValue(game.lives);
}	

function bdc( data ) {
    // Decodes data encoded with MIME base64
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_bdc/
    // +       version: 801.921
    // +   original by: Tyler Akins (http://rumkin.com)
    // *     example 1: bdc('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'


    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';

    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;

        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64)      enc += String.fromCharCode(o1);
        else if (h4 == 64) enc += String.fromCharCode(o1, o2);
        else               enc += String.fromCharCode(o1, o2, o3);
    } while (i < data.length);

    return enc;
}

function base64_encode( data ) {
    // Encodes data with MIME base64
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_bec/
    // +       version: 801.921
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Bayron Guevara
    // *     example 1: bec('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';

    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        enc += b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);

    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}

/**
 * @author fordenbacs
 */
function vostiles_animate(){
	var nb;
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){	
		// check to see if valuable at bottom, if so, recreate above.
		for(nb=0;nb<lv[q].num_vostiles;nb++){
			// puts them back on screen somewhere if they reach the bottom.	
			if(vostiles[nb].xdir==0 && vostiles[nb].ydir==0){
				sprite_moveto(vostiles[nb],'vostile');
			}
			sprite_setdir(vostiles[nb],'vostile');
		}	
	}	
}

// if hero runs into a vostile, loss of life-vostile created back at top.
function vostiles_deflect(){
	var m;
	for(m=0;m<lv[q].num_vostiles;m++){
		if(hero.hasHit(vostiles[m])){
			sprite_moveto(vostiles[m],'vostile');
			sprite_setdir(vostiles[m],'vostile');
			game.lives=game.lives-1;
			in_lives_interlude='yes';
			show_score();
		} 
	}
}
	
function vostiles_init(){
	var n;
	for(n=0;n<lv[q].num_vostiles;n++){				
		vostile_add(n);
	}
}

function vostile_add(x){
	vostiles[x]=new Sp_Sprite()	
	vostiles[x].setImage(game.vostile_image,game.vostile_width,game.vostile_height,1,1); 
	vostiles[x].setXlimits(100,game.screen_width+100);
	
	if ((game.gtype == 'Shooting Gallery') || (game.gtype == 'Catching Things') || (game.gtype == 'Classic')) {	
		vostiles[x].setYlimits(50,game.screen_height-25);
	} else { 
		vostiles[x].setYlimits(50,game.screen_height+50);
    }
	vostiles[x].setFrame(0);		
	vostiles[x].setAnimationLoop(0,1);	
	vostiles[x].setAnimationSpeed(2,"forward"); 
	vostiles[x].setAnimation(0);	
	vostiles[x].setSpeed(Math.random()*lv[q].vostile_speed_seed+lv[q].vostile_speed_adder);		
	vostiles[x].setAnimationRepeat(-1);	
 	if (game.vostile_dir == 'top to bottom') {
		vostiles[x].setDir(0,1);
	}
	if (game.vostile_dir == 'bottom to top') {
		vostiles[x].setDir(0,-1);
	}
	if (game.vostile_dir == 'right to left') {
		vostiles[x].setDir(1,0);
	}
	if (game.vostile_dir == 'left to right') {
		vostiles[x].setDir(-1,0);
	}
	vostiles[x].collides=true;
	vostiles[x].useHitEvents(true);
}

function vostiles_start(){
	var n;
	vostiles_init();	
	for(n=0;n<lv[q].num_vostiles;n++){				
		vostile_start(n);
	}
}

function vostile_start(x){
	sprite_moveto(vostiles[x],'vostile');
	vostiles[x].switchOn();	
}

function vostiles_end(){
	var n;
	for(n=0;n<lv[q].num_vostiles;n++){				
		vostile_end(n);
	}
}

function vostile_end(x){
	vostiles[x].switchOff();
	vostiles[x].destroy();	
}

/**
 * @author fordenbacs
 */
 
 
 
 
function bullets_animate(){

	if ((in_levels_interlude == 'no') && (in_lives_interlude == 'no')){
		// check to see if valuable at bottom, if so, recreate above.
		
		nb=0;
		while (nb < game.num_bullets) {
			if (game.gtype == 'Bomb Drop') {
				// if reach end of screen, end bullet.
                 //var bnby=bullets[nb].y;
				 if (bullets[nb].y > 500) { 
					bullet_end(nb);
				 }
				// set direction
				sprite_setdir(bullets[nb],'bullet');
				nb=nb+1; 
			} else {	
				// if reach end of screen, end bullet.	
				 if (bullets[nb].y < 50) { 
					bullet_end(nb);
				 }
				// set direction
				sprite_setdir(bullets[nb],'bullet');
				nb= nb+1; 
   		 	}
		}	
	}
}

// if bullet hits a hostile, get points , and destroy hostile, and bullet..
function bullets_deflect(){
	var b,v;
	if (game.canshootvostile == 'yes') {
		b=0;
		while(b<game.num_bullets){
		    v=0; 
		 	while(v<lv[q].num_vostiles){
				if(bullets[b].hasHit(vostiles[v])){
			 		//end bullet, reposition hostile, grant points
			 		//alert('has hit');
					bullet_end(b); 		
					sprite_moveto(vostiles[v],'vostile');
					sprite_setdir(vostiles[v],'vostile');
					if (game.gtype == 'Shooting Gallery') {
						game.lives=game.lives-1;
						in_lives_interlude='yes';
						show_score();
					} else {
						game.score=game.score+game.vostile_points;
						show_score();
					} 
				} 
			v=v+1;	
			}
			b=b+1;	
		}
	}
	
	if (game.canshoothostile == 'yes') {
		b=0;
		while(b<game.num_bullets){
		    v=0; 
		 	while(v<lv[q].num_hostiles){
				if(bullets[b].hasHit(hostiles[v])){
			 		//end bullet, reposition hostile, grant points
			 		//alert('has hit');
					bullet_end(b); 		
					sprite_moveto(hostiles[v],'hostile');
					sprite_setdir(hostiles[v],'hostile');
					game.score=game.score+game.hostile_points;
					show_score();
				} 
			v=v+1;	
			}
			b=b+1;	
		}
	}	
	
	if (game.canshootvaluables == 'yes') {
		b=0;
		while(b<game.num_bullets){
		    v=0; 
		 	while(v<lv[q].num_valuables){
				if(bullets[b].hasHit(valuables[v])){
			 		//end bullet, reposition hostile, grant points
			 		//alert('has hit');
					bullet_end(b); 		
					sprite_moveto(valuables[v],'valuable');
					sprite_setdir(valuables[v],'valuable');
					game.score=game.score+game.valuable_points;
					show_score();
				} 
			v=v+1;	
			}
			b=b+1;	
		}
	}	
	if (game.canshoothelper == 'yes') {
		b=0;
		while(b<game.num_bullets){
				if(bullets[b].hasHit(helper)){
			 		//end bullet, reposition hostile, grant points
			 		//alert('has hit');
					bullet_end(b); 
					// don't move helper, just let him keep going.
					// maybe some indicatin there was points.		
					//sprite_moveto(valuables[v],'valuable');
					//sprite_setdir(valuables[v],'valuable');
					game.score=game.score+game.valuable_points;
					show_score();
				} 
			b=b+1;	
		}
	}	
	
	
}

function bullets_start(){

	bullets_init();	

}

function bullets_init(){
	var b=0;
	while(b<game.num_bullets){
		bullet_add(b);
		bs[b]='avail';
		b=b+1;	
	}
}

function bullet_add(x){
	bullets[x]=new Sp_Sprite()	
	bullets[x].setImage(game.bullet_image,game.bullet_width,game.bullet_height,1,1); 
	bullets[x].setXlimits(100,game.screen_width+100);	
	bullets[x].setYlimits(50,game.screen_height+50);	
	bullets[x].setFrame(0);		
	bullets[x].setAnimationLoop(0,1);	
	bullets[x].setAnimationSpeed(2,"forward"); 
	bullets[x].setAnimation(0);	
	bullets[x].setSpeed(20);
	//bullets[x].setSpeed(5);		
	bullets[x].setAnimationRepeat(-1);
	bullets[x].collides=true;
	bullets[x].useHitEvents(true);
	if ((game.gtype=='Shooting Ball') || (game.gtype=='Shooting Gallery')){
		bullets[x].moveTo(1,500);
	} else { 
		bullets[x].moveTo(1,1);
	}
	bullets[x].switchOff();
}




function bullet_fire(){
 	//alert('firing');
 	var bf=0;
 	while (bf < game.num_bullets) {
 	    if (bs[bf] == 'avail') {
			switch(game.gtype) {
	   		    case 'Bomb Drop':
					//bullets[bf].moveTo(hero.x+10,hero.y+25+game.hero_height);
					bullets[bf].moveTo(hero.x+10,hero.y + parseInt(game.hero_height) + 25);
					break;
				default:
					bullets[bf].moveTo(hero.x+10,hero.y-25);
					break;
			}
			bullets[bf].switchOn();
			sprite_setdir(bullets[bf],'bullet');
			bs[bf]= 'unavail';
			// kick out of routine
			bf= game.num_bullets+1;
		}
	bf= bf+1;	
	}
}

//function bullets_end(){
	//var n;
	//for(n=0;n<num_bullets;n++){				
		//bullet_end(n);
	//}
//}

function bullet_end(x){
    bs[x]='avail';
    //bullets[x].moveTo(100,100);
	bullets[x].switchOff();
	//bullets[x].destroy();	
}

/**
 * @author fordenbacs
 **/
// hero follows the mouse.
function hero_animate(){
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){	

		//if (!hero.hasHit(wall)) {
			hero.moveTo(mymouse.x,mymouse.y);	
		//} else {
	        // has hit
			//if (mymouse.x < wall.x) {
				//hero.moveTo(mymouse.x,mymouse.y);
			//}
		//}

		 
		if (mymouse.mousedown) {
  		   bullet_fire();
		}

		switch(game.gtype) {
		case 'Shooting Gallery':
			valuables_deflect();
			hostiles_deflect();
			vostiles_deflect();
			break;
		case 'Shooting Ball':
			helper_deflect();
			//valuables_deflect();
			hostiles_deflect();
			//vostiles_deflect();
			break;
		case 'Bomb Drop':
			valuables_deflect();
			hostiles_deflect();
			vostiles_deflect();
			break;
		case 'Catching Things':
			valuables_deflect();
			hostiles_deflect();
			vostiles_deflect();
			break;
		default:
			valuables_deflect();
			hostiles_deflect();
			vostiles_deflect();
		}
	}	
};

function hero_init(){
	hero=new Sp_Sprite()
	hero.setImage(game.hero_image,game.hero_width,game.hero_height,1,1);
	//hero.resize(lv[q].hero_width,lv[q].hero_height);
	switch(game.gtype) { 
		case 'Shooting Gallery':
		    hero.setXlimits(100,game.screen_width+100);	
		    hero.setYlimits(450,550);
		    break; 
		case 'Shooting Ball':
		    hero.setXlimits(100,game.screen_width+100);	
		    hero.setYlimits(450,550);
		    break; 
		case 'Bomb Drop':
		    hero.setXlimits(100,game.screen_width+100);	
		    hero.setYlimits(100,200);
		    break; 
		case 'Catching Things':
		    hero.setXlimits(100,game.screen_width+100);	
			hero.setYlimits(100,550);
			break;
		default: 
		 	hero.setXlimits(game.hero_x_limit_left,game.hero_x_limit_right);	
			hero.setYlimits(game.hero_y_limit_top,game.hero_y_limit_bottom);
			break;
	}		 
	hero.setFrame(0);		
	hero.setAnimationLoop(0,1);	
	hero.setAnimationSpeed(2,"forward"); 
	hero.setAnimation(0);	
	hero.setSpeed(4);		
	hero.setAnimationRepeat(-1);	
	hero.collides=true;
	hero.useHitEvents(true);
	//hero.hard=true;	
};

function hero_start(){
	hero.moveTo(game.hero_start_x,game.hero_start_y);
	hero.switchOn();	
};	

function hero_end(){
	hero.switchOff();	
};

/**
 * @author fordenbacs
 */
function hostiles_animate(){
	var nb;
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){	
		// check to see if valuable at bottom, if so, recreate above.
		for(nb=0;nb<lv[q].num_hostiles;nb++){
			// puts them back on screen somewhere if they reach the bottom.	
			if(hostiles[nb].xdir==0 && hostiles[nb].ydir==0){
				//in catching game, if reach bottom,lost life
				if (game.gtype == 'Catching Things') {
					game.lives=game.lives-1;
					in_lives_interlude='yes';
					show_score();
					sprite_moveto(hostiles[nb],'hostile');
		 		} else {
				 	sprite_moveto(hostiles[nb],'hostile');
				} 
			}
			sprite_setdir(hostiles[nb],'hostile');
		}	
	}	
};

// if hero runs into a valuable, get points and play sound, and recreate valuable at top.
function hostiles_deflect(){
	var m;
	for(m=0;m<lv[q].num_hostiles;m++){
		if(hero.hasHit(hostiles[m])){
			sprite_moveto(hostiles[m],'hostile');
			sprite_setdir(hostiles[m],'hostile');
			game.score=game.score+lv[q].hostile_points;
			show_score();
		} 
		if (game.gtype == 'Shooting Ball') {
			var b=0;
			while(b<game.num_bullets){
					if(bullets[b].hasHit(hostiles[m])){
				 		//end bullet, reposition hostile, grant points
				 		//alert('has hit');
						bullet_end(b); 
						sprite_moveto(hostiles[m],'hostile');
						sprite_setdir(hostiles[m],'hostile');
						game.lives=game.lives-1;
						in_lives_interlude='yes';
						show_score();
					} 
				b=b+1;	
			}
		}
	}
};
	
function hostiles_init(){
	var n;
	for(n=0;n<lv[q].num_hostiles;n++){				
		hostile_add(n);
	}
};

function hostile_add(x){
	hostiles[x]=new Sp_Sprite()	
	hostiles[x].setImage(game.hostile_image,game.hostile_width,game.hostile_height,1,1); 
    //if (game.gtype == 'Shooting Gallery') {
		//hostiles[x].setXlimits(100,game.screen_width+100);	
		//hostiles[x].setYlimits(100,200);
    //} else { 
		//hostiles[x].setXlimits(100,game.screen_width+100);	
		//hostiles[x].setYlimits(50,game.screen_height+50);	
	//}
	switch(game.gtype) { 
		case 'Shooting Gallery':
		hostiles[x].setXlimits(100,game.screen_width+25);	
		hostiles[x].setYlimits(100,250);
		break; 
		case 'Shooting Ball':
		hostiles[x].setXlimits(100,game.screen_width+50);	
		hostiles[x].setYlimits(175,325);
		break; 
		case 'Bomb Drop':
		hostiles[x].setXlimits(100,game.screen_width+100);	
		hostiles[x].setYlimits(480,580);
		break; 
		case 'Catching Things':
		hostiles[x].setXlimits(100,game.screen_width+100);	
		hostiles[x].setYlimits(50,game.screen_height-25);	
		break;
		default: 
		hostiles[x].setXlimits(100,game.screen_width+100);	
		hostiles[x].setYlimits(50,game.screen_height-25);	
		break;
	}
	
	hostiles[x].setFrame(0);		
	hostiles[x].setAnimationLoop(0,1);	
	hostiles[x].setAnimationSpeed(2,"forward"); 
	hostiles[x].setAnimation(0);	
	hostiles[x].setSpeed(Math.random()*lv[q].hostile_speed_seed+lv[q].hostile_speed_adder);		
	hostiles[x].setAnimationRepeat(-1);	
	if (game.hostile_dir == 'top to bottom') {
		hostiles[x].setDir(0,1);
	}
	if (game.hostile_dir == 'bottom to top') {
		hostiles[x].setDir(0,-1);
	}
	if (game.hostile_dir == 'right to left') {
		hostiles[x].setDir(1,0);
	}
	if (game.hostile_dir == 'left to right') {
		hostiles[x].setDir(-1,0);
	}
	hostiles[x].collides=true;
	hostiles[x].useHitEvents(true);
};

function hostiles_start(){
	var n;
	hostiles_init();	
	for(n=0;n<lv[q].num_hostiles;n++){				
		hostile_start(n);
	}
};

function hostile_start(x){
	sprite_moveto(hostiles[x],'hostile');
	hostiles[x].switchOn();	
};

function hostiles_end(){
	var n;
	for(n=0;n<lv[q].num_hostiles;n++){				
		hostile_end(n);
	}
};

function hostile_end(x){
    if (hostiles[x]) {
		hostiles[x].switchOff();
		hostiles[x].destroy();	
	}
};

/**
 * @author fordenbacs
 */
function meanies_animate() {
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){	
		for(n=0;n<lv[q].num_meanies;n++){
			entourage_draw(n);
			//alert('game.mn[n].direct:' + game.mn[n].direct);
			if (game.mn[n].path == 'square') {
				game.mn[n].counter=game.mn[n].counter+1;
				//alert('b4 game.mn[n].counter:' + game.mn[n].counter);
				if (game.mn[n].counter>=20) {
					//alert('in game.mn[n].counter:' + game.mn[n].counter);	
					if(game.mn[n].cdir==1){
						game.meanies[n].setDir(0,-1)
					}
					if(game.mn[n].cdir==2){
						game.meanies[n].setDir(-1,0)
					}
					if(game.mn[n].cdir==3){
						game.meanies[n].setDir(0,1)
					}
					if(game.mn[n].cdir==0){
						game.meanies[n].setDir(1,0)
					}
					game.mn[n].counter=0;
					//alert('game.mn[n].direct:' + game.mn[n].direct);
					if (game.mn[n].direct=='clockwise') {
						game.mn[n].cdir=game.mn[n].cdir+1;
					} else {
						game.mn[n].cdir=game.mn[n].cdir-1;	
					}	
					if (game.mn[n].cdir<0) {
						game.mn[n].cdir=3;
					}			
					if (game.mn[n].cdir>3) {
						game.mn[n].cdir=0;
					}
				}
	 		}
		}	
	}
}

// if hero runs into a meanie, loses life.
function meanies_hit(){
	var m;
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){	
		for(m=0;m<lv[q].num_meanies;m++){
			if(hero.hasHit(game.meanies[m])){
				game.lives=game.lives-1;
				show_score();
				in_lives_interlude='yes';
				hero.moveTo(game.hero_start_x,game.hero_start_y);
				meanies_end();
				
				meanies_start();
				clear_trail();

			} 
			// now check followers of the meanie
			follower_hit(m);
		}
	}	
}

function meanies_init(){
	var n;					
	for(n=0;n<lv[q].num_meanies;n++){				
		meanie_add(n);
		if (lv[q].has_entourage == 'YES') {
			entourage_init(n);
		}
	}
}

function meanie_add(x){
	game.meanies[x]=new Sp_Sprite();
	game.mn[x]=new meanie_status()	
	game.mn[x].counter=20;
	game.mn[x].path=game.meanies_path[x];
	game.mn[x].direct=game.meanies_direct[x];
	game.mn[x].cdir=game.meanies_cdir[x];
	// target hero
	if (game.mn[x].path == 'target hero') {
		game.meanies[x].target(hero,1,1);	
	}
	// square
	if (game.mn[x].path == 'square') {
		game.mn[x].cdir=game.mn[x].cdir;
		game.meanies[x].setDir(0,-1);	
		game.mn[x].direct=game.mn[x].direct;
	}	
	// top - bottom
	if (game.mn[x].path == 'top-bottom') {
		game.mn[x].cdir=game.mn[x].cdir;
		game.meanies[x].setDir(0,-1);	
		game.mn[x].direct=game.mn[x].direct;
	}	
	game.meanies[x].setImage(game.meanie_image,game.meanie_width,game.meanie_height,1,1);
	game.meanies[x].resize(game.meanie_width,game.meanie_height);  
	game.meanies[x].setXlimits(100,game.screen_width+100);	
	game.meanies[x].setYlimits(50,game.screen_height+50);
	game.meanies[x].setFrame(0);	
	game.meanies[x].setAnimationLoop(0,1);
	game.meanies[x].setAnimationSpeed(2,"forward"); 
	game.meanies[x].setAnimation(0);
	game.meanies[x].setSpeed(4);	
	game.meanies[x].setAnimationRepeat(-1);	
	game.meanies[x].collides=true;
	game.meanies[x].useHitEvents(true);
}

function meanies_start(){	
	var n;
	entourage_init();
	meanies_init();
	for(n=0;n<lv[q].num_meanies;n++){				
		meanie_start(n);
		followers_start(n);
	}
}

function meanie_start(x){
	if (lv[q].num_meanies == 3) { 
		if (x == 0) {
			game.meanies[x].moveTo(300,20);	
		}	
		if (x == 1) {
			game.meanies[x].moveTo(150,150);		
		}
		if (x == 2) {
			game.meanies[x].moveTo(500,150);		
		}
	}
	if(lv[q].num_meanies == 2) {
		if (x == 0) {
			game.meanies[x].moveTo(300,20);	
		}	
		if (x == 1) {
			game.meanies[x].moveTo(150,150);		
		}
	}
	if(lv[q].num_meanies == 1) {
		if (x == 0) {
			game.meanies[x].moveTo(150,150);	
		}	
	}		
	game.meanies[x].switchOn();	
}

function meanies_end(){	
	var n;				
	for(n=0;n<lv[q].num_meanies;n++){				
		meanie_end(n);
		followers_end(n);
	}
}

function meanie_end(x){
	game.meanies[x].switchOff();
	game.meanies[x].destroy();
	//game.mn[x]= null;
}

/**
 * @author fordenbacs
 */
function valuables_animate(){
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){
		// check to see if valuable at bottom, if so, recreate above.
		for(nd=0;nd<lv[q].num_valuables;nd++){
			// bottom puts them back on screen somewhere if they reach the bottom.	
			if(valuables[nd].xdir==0 && valuables[nd].ydir==0){
				sprite_moveto(valuables[nd],'valuable');
			}
			// set direction
			sprite_setdir(valuables[nd],'valuable');
		}
	}	
};

// if hero runs into a valuable, get points and play sound, and recreate valuable at top.
function valuables_deflect(){
	var m;
	for(m=0;m<lv[q].num_valuables;m++){
		if(hero.hasHit(valuables[m])){
			//hostiles[m].moveTo(Math.random()*lv[q].screen_width,Math.random()*200);		
			sprite_moveto(valuables[m],'valuable');
			sprite_setdir(valuables[m],'valuable');
			game.score=game.score+lv[q].valuable_points;
			show_score();
		} 
	}
};

function valuables_init(){
	var n;
	for(n=0;n<lv[q].num_valuables;n++){	
		valuable_add(n);
	}
};

function valuable_add(x){
	valuables[x]=new Sp_Sprite()	
	valuables[x].setImage(game.valuable_image,game.valuable_width,game.valuable_height,1,1);
	//if (game.gtype == 'Shooting Gallery') {
		////valuables[x].setXlimits(100,game.screen_width+100);	
		//valuables[x].setYlimits(100,200);
    //} else {  
		//valuables[x].setXlimits(100,game.screen_width+100);	
		//valuables[x].setYlimits(50,game.screen_height+50);	
	//}
	switch(game.gtype) { 
		case 'Shooting Gallery':
		valuables[x].setXlimits(100,game.screen_width+25);	
		valuables[x].setYlimits(100,250);
		break; 
		case 'Shooting Ball':
		valuables[x].setXlimits(100,game.screen_width+100);	
		valuables[x].setYlimits(100,200);
		break; 
		case 'Bomb Drop':
		valuables[x].setXlimits(100,game.screen_width+100);	
		valuables[x].setYlimits(480,580);
		break; 
		case 'Catching Things':
		valuables[x].setXlimits(100,game.screen_width+100);	
		valuables[x].setYlimits(50,game.screen_height-25);	
		break;
		default: 
		valuables[x].setXlimits(100,game.screen_width+100);	
		valuables[x].setYlimits(50,game.screen_height-25);	
		break;
	}

	valuables[x].setFrame(0);		
	valuables[x].setAnimationLoop(0,1);	
	valuables[x].setAnimationSpeed(2,"forward"); 
	valuables[x].setAnimation(0);	
	valuables[x].setSpeed(Math.random()*lv[q].valuable_speed_seed+lv[q].valuable_speed_adder);		
	valuables[x].setAnimationRepeat(-1);
	valuables[x].collides=true;
	valuables[x].useHitEvents(true);
};

function valuables_start(){
	var n;
	valuables_init();	
	for(n=0;n<lv[q].num_valuables;n++){				
		valuable_start(n);
	}
};

function valuable_start(x){
	sprite_setdir(valuables[x],'valuable');
	sprite_moveto(valuables[x],'valuable');	
	valuables[x].switchOn();	
};

function valuables_end(){
	var n;
	for(n=0;n<lv[q].num_valuables;n++){				
		valuable_end(n);
	}
};

function valuable_end(x){
	valuables[x].switchOff();
	valuables[x].destroy();	
};

/**
 * @author fordenbacs
 */
// helper puts out fires.

function helper_animate(){
    var hold_hostile_dir=game.hostile_dir;
    if (game.gtype == 'Shooting Ball') {
    	game.hostile_dir='top to bottom';
    } 
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){	
		if(helper.xdir==0 && helper.ydir==0){
			if (game.hostile_dir == 'top to bottom') {
				// set direction goes right to left along bottom
				if (helper.x <=100) {
					helper.setDir(1,0);
				} else {
					helper.setDir(-1,0);
				}
				//if (helper.x <=100) {
				 	//helper.x=100;
					//helper.setDir(1,0);
				//} else {
					//if (helper.x >550) {
				 	    //helper.x=550;
						//helper.setDir(-1,0);
					//}
				//}	
				
			}
			if (game.hostile_dir == 'bottom to top') {
				// set direction goes right to left along top
				//if (helper.x <=100) {
					//helper.setDir(1,0);
				//} else {
					//helper.setDir(-1,0);
				//}
				if (helper.x <=100) {
				 	helper.x=100;
					helper.setDir(1,0);
				} else {
					if (helper.x >550) {
					 	helper.x=550;
						helper.setDir(-1,0);
					}
				}	
				
			}
			if (game.hostile_dir == 'right to left') {
				// set direction goes top to bottom on left 
				if (helper.y <=100) {
					helper.setDir(0,1);
				} else {
					helper.setDir(0,-1);
				}
			}
			if (game.hostile_dir == 'left to right') {
				// set direction goes top to bottom on right 
				if (helper.y <=100) {
					helper.setDir(0,1);
				} else {
					helper.setDir(0,-1);
				}
			}		
		}

	}
	if (game.gtype == 'Shooting Ball') {
    	game.hostile_dir=hold_hostile_dir;
    } 	
}


// if helper runs into a target, put it out, give points and play sound
function helper_deflect(){
 	if (game.gtype != 'Shooting Ball') {
		var m;
		for(m=0;m<lv[q].num_targets;m++){
			if(helper.hasHit(targets[m])){
				if (hs[m].burning=='yes') {
					targets[m].switchOff();
					sprite_moveto(targets[m],'target');
					targets[m].switchOn();
					hs[m].hit='no';
					hs[m].onfire=0;
					hs[m].burning='no';
					targets[m].setFrame(0);		
					targets[m].setAnimationLoop(0,1);
					targets[m].setAnimationSpeed(2,"forward");
					targets[m].setAnimation(0);			
					targets[m].setSpeed(4);			
					targets[m].setAnimationRepeat(-1);			
					game.score=game.score+lv[q].valuable_points;
					show_score();
				} 
			}
		}
	} else {
	 	var b=0;
		while(b<game.num_bullets){
			if(bullets[b].hasHit(helper)){
				//end bullet, reposition hostile, grant points
		 		//alert('has hit');
				bullet_end(b); 
				//sprite_moveto(hostiles[m],'hostile');
				//sprite_setdir(hostiles[m],'hostile');
				//game.lives=game.lives-1;
				//in_lives_interlude='yes';
				game.score=game.score+lv[q].hostile_points;
				show_score();
			} 
			b=b+1;	
		}
	} 
}


function helper_init(){
	helper=new Sp_Sprite()
	helper.setImage(game.helper_image,game.helper_width,game.helper_height,1,1); 
	if (game.gtype == 'Shooting Ball') {
	 	helper.setXlimits(100, game.screen_width+100);	
		helper.setYlimits(50, 150);	
	} else { 
		helper.setXlimits(100, game.screen_width+100);	
		helper.setYlimits(50, game.screen_height+50);	
	}
	
	helper.setFrame(0);		
	helper.setAnimationLoop(0,1);	
	helper.setAnimationSpeed(2,"forward"); 
	helper.setAnimation(0);	
	helper.setSpeed(8);
	helper.setAnimationRepeat(-1);	
	helper.collides=true;
	helper.useHitEvents(true);
}

function helper_start(){
	sprite_moveto(helper,'helper');
	sprite_setdir(helper,'helper');
	helper.switchOn();	
}	

function helper_end(){
	helper.switchOff();	
}

/**
 * @author fordenbacs
 */
function targets_animate(){
	var n;
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){	
		//set if target is hit.
		for(n=0;n<lv[q].num_targets;n++){
			target_light(n);
			if (hs[n].hit == 'yes' ) {
				target_burn(n);
			}
		}	
	}	
}

function targets_init(){	
	var n;				
	for(n=0;n<lv[q].num_targets;n++){				
		target_add(n);
	}
}

function target_add(x){
	targets[x]=new Sp_Sprite()	
	hs[x]=new target_status()	
	hs[x].hit='no';
	hs[x].onfire=0;
	hs[x].burning='no';
	targets[x].setImage(game.target_image,game.target_width,game.target_height,2,2); 
	targets[x].setXlimits(game.targets_x_limit_left,game.targets_x_limit_right);	
	targets[x].setYlimits(game.targets_y_limit_top,game.targets_y_limit_bottom);	
	targets[x].setFrame(0);	
	targets[x].setAnimationLoop(0,1);
	targets[x].setAnimationSpeed(2,"forward"); 
	targets[x].setAnimation(0);
	targets[x].setSpeed(4);		
	targets[x].setAnimationRepeat(-1);	
	targets[x].collides=true;
	targets[x].useHitEvents(true);
}

function targets_start(){
	var n;	
	targets_init();
	for(n=0;n<lv[q].num_targets;n++){				
		target_start(n);
	}
}

function target_start(x){
	sprite_moveto(targets[x],'target');
	targets[x].switchOn();	
}

function targets_end(){	
	var n;				
	for(n=0;n<lv[q].num_targets;n++){				
		target_end(n);
	}
}

function target_end(x){
	targets[x].switchOff();
	targets[x].destroy();
	//hs[x]= null;
}

//burn target for 50 frames, then delete points, and recreate target in new spot.
function target_burn(hn){
	hs[hn].onfire =	hs[hn].onfire + 1;
	if (hs[hn].onfire > game.on_fire_time ) {
		hs[hn].hit='no';		
		hs[hn].onfire = 0;
		hs[hn].burning='no';
		sprite_moveto(targets[hn],'target');
		targets[hn].setFrame(0);		
		targets[hn].setAnimationLoop(0,1);
		targets[hn].setAnimationSpeed(2,"forward");
		targets[hn].setAnimation(0);			
		targets[hn].setSpeed(4);			
		targets[hn].setAnimationRepeat(-1);
		life_loss();
		show_score();
	}
}

// set target on fire if hit by big darts.
function target_light(hn){
	var m;
	for(m=0;m<lv[q].num_hostiles;m++){
		if(targets[hn].hasHit(hostiles[m])){
 	 		hs[hn].hit ='yes';
			hs[hn].burning='yes';
			hs[hn].onfire=0;
			targets[hn].setFrame(1);
			targets[hn].setAnimationLoop(0,2);
			targets[hn].setAnimationSpeed(2,"forward");
			targets[hn].setAnimation(0);			
			targets[hn].setSpeed(4);			
			targets[hn].setAnimationRepeat(-1);
		} 
	}
}

/**
 * @author fordenbacs
 */
function entourage_draw(in_e){
	var w,p,i;
	//increment trail counter.
	trailIX=trailIX+1;
	if (trailIX > game.follower_trail_array_size) {
		trailIX=0;
	}
	//load current meanie position
	trail[trailIX]=null;
	trail[trailIX]=new Position(game.meanies[in_e].x,game.meanies[in_e].y,myDir);
	//alert('trailIX: ' + trailIX + ' trail[trailIX].x: ' + trail[trailIX].x + 'trail[trailIX].y: ' + trail[trailIX].y + ' trail[trailIX].r: ' + trail[trailIX].r);
	i=game.follower_distance;
	// position followers
	for(w=0;w<lv[q].num_followers;w++){
		i = i + game.follower_distance;
		p=trailIX-i;
		if (p < 0) {
			p=p+game.follower_trail_array_size;
		}
		if (p < trailIX) {
			if (trail[p].x > 0) {
				//game.entourage[in_e][n].setFrame(trail[p].r);
				game.entourage[in_e][w].moveTo(trail[p].x,trail[p].y);
			}
		}
	}
}

function entourage_init(){	
	var e;				
	if (lv[q].has_entourage == 'YES') {
		for(e=0;e<lv[q].num_meanies;e++){
			//alert('e: ' + e + ' q: ' + q + ' lv[q].num_meanies: ' + lv[q].num_meanies);
			entourage_add(e);
		}
	}
}

function entourage_add(in_e){
	var f;
	for(f=0;f<lv[q].num_followers;f++){	
		followers_add(in_e,f);
	}
}	



function followers_add(in_e,in_f){
	game.entourage[in_e][in_f]=new Sp_Sprite();
	game.entourage[in_e][in_f].setImage(game.meanie_image,game.meanie_width,game.meanie_height,1,1); 
	game.entourage[in_e][in_f].setXlimits(100,game.screen_width+100);	
	game.entourage[in_e][in_f].setYlimits(50,game.screen_height+50);
	game.entourage[in_e][in_f].setFrame(0);	
	game.entourage[in_e][in_f].setAnimationLoop(0,1);
	game.entourage[in_e][in_f].setAnimationSpeed(2,"forward"); 
	game.entourage[in_e][in_f].setAnimation(0);
	game.entourage[in_e][in_f].setSpeed(4);	
	game.entourage[in_e][in_f].setAnimationRepeat(-1);	
	game.entourage[in_e][in_f].collides=true;
	game.entourage[in_e][in_f].useHitEvents(true);
}

function followers_start(in_e){
	var f;	
	for(f=0;f<lv[q].num_followers;f++){				
		follower_start(in_e,f);
	}
}

function follower_start(in_e,in_f){
	game.entourage[in_e][in_f].switchOn();
}

function followers_end(in_e){	
	var f;				
	for(f=0;f<lv[q].num_followers;f++){				
		follower_end(in_e,f);
	}
}

function follower_end(in_e,in_f){
	game.entourage[in_e][in_f].switchOff();
	game.entourage[in_e][in_f].destroy();
	//game.entourage[in_e][in_f]= null;
}

function clear_trail() {
	var f;
	var m;
	trailIX=0;
	for(f=0;f<lv[q].num_followers;f++){				
		trail[f]=null;
		for(m=0;m<lv[q].num_meanies;m++){	
			game.entourage[m][f].moveTo(0,0);
		}	
	}
}

// if hero runs into a meanie follower, loses life.
function follower_hit(in_e){
	var in_f;
	if ((in_levels_interlude =='no') && (in_lives_interlude =='no')){	
		for(in_f=0;in_f<lv[q].num_followers;in_f++){
			if(hero.hasHit(game.entourage[in_e][in_f])){
				game.lives=game.lives-1;
				show_score();
				in_lives_interlude='yes';
				hero.moveTo(game.hero_start_x,game.hero_start_y);
				meanies_end();
				meanies_start();
				clear_trail();
			} 
		}
	}	
}
