// Board object
//***************************************************************************************************


function Board(){

this.imagefile=[
"scrub","wood","grass","grass","wood","house","vroad","wood","wood","scrub",
"grass","wood","scrub","grass","wood","scrub","vroad","house","wood","grass",
"scrub","grass","sett","scrub","grass","grass","vroad","house","scrub","wood",
"grass","scrub","grass","wood","scrub","house","vroad","grass","grass","scrub",
"wood","scrub","grass","wood","wood","wood","vroad","house","grass","scrub",
"grass","wood","scrub","wood","grass","house","vroad","grass","scrub","wood",
"grass","scrub","house","grass","house","house","vroad","wood","scrub","grass",
"hroad","hroad","hroad","hroad","hroad","hroad","croad","hroad","hroad","hroad",
"house","grass","scrub","house","wood","grass","vroad","scrub","house","house",
"grass","wood","scrub","grass","grass","scrub","vroad","house","wood","grass"];


//data
this.across = new Array(100);
this.overlayfile = new Array(100);
this.validmove = new Array(100);
this.food = new Array(100);
this.danger = new Array(100);
this.foodmax = new Array(100);
this.sett=22;

//methods
this.DisplayBoard = DisplayBoard;
this.MakeBoard = MakeBoard;
//this.OverlayBoard = OverlayBoard;
this.GetValidMoves = GetValidMoves;
this.BoardClick = BoardClick;
this.GetBoard = GetBoard;
this.GetOverlay = GetOverlay;
}

function DisplayBoard() {
	//display board
	document.write(this.GetBoard());
}


function refreshOverlay(){
	var str=board.GetOverlay();
	document.getElementById('overlayContainer').innerHTML=str;

}

function refreshBoard(){
	var str=board.GetBoard();
  	document.getElementById('cell3').innerHTML=str;
	refreshOverlay()
}

function GetBoard(){
	n=0;
	var r="";
	r+='<table cellspacing="0" cellpadding="0" ><tbody>';
	for(y=0;y<10;y++){
		r+="<tr>";
		for(x=0;x<10;x++) {
			r+='<td class="displayBoard" >';
			r+='<img border="0"  src="images/'+ this.imagefile[n]+'.jpg"';
			r+='">';
			r+="</td>";
			n++;
			}
		
		r+='</tr>';
		}
	r+="</tbody></table>";
	return(r);
}




function MakeBoard() {
	//create a new board
	
	for(n=0;n<100;n++){
		this.overlayfile[n]="blank";
		this.validmove[n]="O";
		this.across[n]=false;
		switch(this.imagefile[n]){
			case "grass":
			case "sett":
				this.foodmax[n]=3;
		  		this.food[n]=getSeasonalFood(this.foodmax[n]);
		  		this.danger[n]=2;
				break;
			case "vroad":
			case "hroad":
				this.foodmax[n]=3;
		  		this.food[n]=getSeasonalFood(this.foodmax[n]);
				this.danger[n]=rand(5)+5;
		  		this.across[n]=true;
				break;
			case "croad":
				this.foodmax[n]=8;
		  		this.food[n]=getSeasonalFood(this.foodmax[n]);
				this.danger[n]=10+rand(2);
		  		this.across[n]=true;
				break;
			case "scrub":
				this.foodmax[n]=5;
		  		this.food[n]=getSeasonalFood(this.foodmax[n]);
				this.danger[n]=3;
		  		break;
		  	case "wood":
				this.foodmax[n]=8;
		  		this.food[n]=getSeasonalFood(this.foodmax[n]);
				this.danger[n]=3;
		  		break;
		  	case "house":
				this.foodmax[n]=rand(7)+5;
		  		this.food[n]=this.foodmax[n];
		  		this.danger[n]=rand(7)+3;
		  		break;
		  	}

		}
	//sett
	this.overlayfile[this.sett]="claim";
	//enemy
	this.overlayfile[rand(50)+49]="nme";

}

function getSeasonalFood(food){
	//adjust food availability according to season
	switch(game.season){
		case "Winter":
			return eval(Math.round(food*0.25));
		case "Spring":
			return eval(Math.round(food*0.5));
		case "Summer":
			return eval(food);
		case "Autumn":
			return eval(Math.round(food*0.5));
	}
}

function replenishTerritories(){
	for(n=0;n<100;n++){	
	 	board.food[n]=getSeasonalFood(board.foodmax[n]);
	 	if(board.imagefile[n]=="house"){
	  		board.food[n]=rand(7)+5;
	  		board.danger[n]=rand(7)+3;	
			}
	 	if(board.imagefile[n]=="wood" && game.season=="Winter") board.food[n]+=2;
		}
}
