function Star(pX,pY,pSpeed,pId,pCol,pDivReference){
	this.x=pX;
   	this.y=pY;
  	this.speed = pSpeed;
   	this.id=pId;
	this.div=pDivReference;
	
	this.ref=this.div.id+"star";
   	this.init=function(){
 		this.div.innerHTML+="<div id="+this.ref+this.id+" style='position:absolute;left:"+pX+";top:"+pY+";color:"+pCol+"'>.</div>";
   	}
   	this.draw=function(){
		stardiv = $(this.ref+this.id).style;
		stardiv.left=this.x;
		stardiv.top=this.y;
    }

	this.move=function(pOffsetSpeed){
		this.x+=this.speed+pOffsetSpeed;
 		if(this.x>TheGame.screenWidth)this.x=0;
		if(this.x<0)this.x=TheGame.screenWidth;
	}
}

function StarLayer(pId, pSpeed, pCol, pDivReference){
  	this.id = pId;
	this.speed = pSpeed;
	this.color = pCol;
	this.stars = new Array();
	this.frameStars = 10;
	this.init=function(){
		for(i=0;i<this.frameStars;i++){
			this.stars[i] = new Star(Math.floor(Math.random()*TheGame.screenWidth), Math.floor(Math.random()*TheGame.screenHeight)-12, this.speed, i+(this.id*this.frameStars), this.color, pDivReference);
			this.stars[i].init();
		}
	}
		
	this.move=function(pOffsetSpeed){
		for(i=0;i<this.frameStars;i++){
			tmpOffset = (pOffsetSpeed/2)/(this.id+1)-2;
			this.stars[i].move(tmpOffset);
		}
	}

	this.draw=function(){
		for(i=0;i<this.frameStars;i++){
			this.stars[i].draw();
		}
	}
}

function StarLayerController(pLayerArray, pDivReference){
	this.starLayers = new Array();
	this.preInit = function(){
	this.offsetSpeed = 0;
		for(j=0;j<pLayerArray.length;j++){
			this.starLayers[j]= new StarLayer(j, pLayerArray[j][0], pLayerArray[j][1], pDivReference);
		}
	}

	this.init = function(){
		 for(j=0;j<this.starLayers.length;j++){
			this.starLayers[j].init();
		}
	}
	this.preInit(); //set up the layer arrays
	this.init();	//init the layers

	this.move = function(pSpeed){
		for(j=0;j<this.starLayers.length;j++){
			this.starLayers[j].offsetSpeed=pSpeed;
			this.starLayers[j].move(pSpeed);
		}
	}
	this.draw=function(){
		for(j=0;j<this.starLayers.length;j++){
			this.starLayers[j].draw();
		}
	}
	
	this.update=function(pOffsetSpeed){
		this.move(pOffsetSpeed);
		this.draw();
	}
}