function Baddie(px,py, pid, pDivReference){
	this.base = ScreenObject;
	this.base(px,py,"baddie",pid,25,25,pDivReference,"bad1.gif");

	this.status=2;
	
	this.pointValue=10;
	this.xspeed=Math.floor(Math.random()*5)+2;
	this.yspeed=(Math.floor(Math.random()*6)-3);

	this.threshold=0;
	this.counter=0;

	this.move = function(){
		switch(this.status){
			case 1:
				if(++this.counter>this.threshold){
					this.counter=0;
					this.threshold=Math.floor(Math.random()*25);
					this.xspeed=(Math.floor(Math.random()*6)-3)+1;
					this.yspeed=(Math.floor(Math.random()*6)-3);
				}
				this.x+=this.xspeed;
				this.y+=this.yspeed;
				
				if(this.x<-60||this.x>TheGame.screenWidth+40)this.xspeed*=-1;
				if(this.y<-60||this.y>TheGame.screenHeight+20)this.yspeed*=-1;

				break;
			case 2:
				this.x-=this.xspeed;
				if(this.x<-20)this.x=TheGame.screenWidth+100;
				this.y+=Math.sin(this.counter)*this.yspeed;
				this.counter+=0.2;
				if(this.counter>5000)this.counter=0;
				break;
			case 3:
				this.x-=this.xspeed;
				if(this.x<-20){
					this.x=TheGame.screenWidth+100;
					this.status=2;
					this.counter=0;
				}
				if(this.y<TheGame.P.y)
					if(!this.y<0)this.y-=this.yspeed;
				else
					if(!this.y>TheGame.screenHeight)this.y+=this.yspeed;
					
				//this.y+=Math.sin(this.counter)*this.yspeed;
				//this.counter+=0.2;
				//if(this.counter>5000)this.counter=0;
				break;
		}
	}
	
	this.checkCol = function(objThing){
		if(((this.x>=objThing.x&&this.x<objThing.x+objThing.width)||(this.x+this.width>=objThing.x&&this.x+this.width<objThing.x+objThing.width))&&((this.y>=objThing.y&&this.y<objThing.y+objThing.height)||(this.y+this.height>=objThing.y&&this.y+this.height<objThing.y+objThing.height))){
			this.remove();
			return true;
		}
	}
	
	this.remove = function(){
		this.status=0;
		this.threshold=10;
		this.counter = 0;
		this.x=-this.width*2;
		this.y=-this.height*2;
		this.draw();
	}
}
//Baddie.protoype = new ScreenObject; //inherits from screenobject

//=========================================================
function BaddieGroupController(pBaddieArray, pDivReference){
//=========================================================
	this.group = Array();
	this.div = pDivReference;
	this.preInit = function(){
		for(j=0;j<pBaddieArray.length;j++){
			this.group[j]= new Baddie(pBaddieArray[j][0], pBaddieArray[j][1], j, this.div);
		}
	}

	this.init = function(){
		 for(j=0;j<this.group.length;j++){
			this.group[j].init();
		}
	}
	this.preInit(); //set up the layer arrays
	this.init();	//init the layers

	this.move = function(){
		for(j=0;j<this.group.length;j++){
			this.group[j].move();
		}
	}
	this.draw=function(){
		for(j=0;j<this.group.length;j++){
			this.group[j].draw();
		}
	}
	
	this.update=function(){
		if(Math.floor(Math.random()*20)==1){
			tmpSize = this.group.length;
			for(j=0;j<this.group.length;j++){
				if(this.group[j].status==0){
					this.group[j].status=3;
					this.group[j].threshold=0;
					this.group[j].x=TheGame.screenWidth+30;
					this.group[j].y=Math.floor(Math.random()*TheGame.screenHeight);
					break;
				}
			}
		}
		this.move();
		this.draw();
	}
	
	this.reset=function(){
		this.group=Array();
		this.preInit();
		this.init();
	}
}

