var CELL_BLACK		= -1;
var CELL_WHITE 		= 0;
var CHECKER_YELLOW 	= 1;
var KING_YELLOW 		= 2;
var CHECKER_GREEN 	= 3;
var KING_GREEN 		= 4;


function Cell(value){
	
	this.value = value;
	
	this.x = null;
	this.y = null;
	
	this.selected = false;
	this.movable = false;
	this.jumpable = false;
	
	
	if(this.value>0){
		this.checker = true;
	}
	else{
		this.checker = false;
	}
	
	
	if(this.value == CELL_WHITE){
		this.empty = true;
	}
	else{
		this.empty = false;
	}
	
	
	if((this.value == CHECKER_YELLOW)||(this.value == KING_YELLOW)){
		this.yellow = true
	}
	else{
		this.yellow = false;
	}
	
	
	if((this.value == CHECKER_GREEN)||(this.value == KING_GREEN)){
		this.green = true
	}
	else{
		this.green = false;
	}
	
	
	if((this.value == KING_YELLOW)||(this.value == KING_GREEN)){
		this.king = true;
	}
	else{
		this.king = false;
	}
		
}


Cell.prototype.setValue = function(value){
	this.value = value;
}

Cell.prototype.setSelected = function(value){
	this.selected = value;
}

Cell.prototype.setMovable = function(value){
	this.movable = value;
}

Cell.prototype.setJumpable = function(value){
	this.jumpable = value;
}

Cell.prototype.setX = function(value){
	this.x = value;
}

Cell.prototype.setY = function(value){
	this.y = value;
}

Cell.prototype.setChecker = function(value){
	this.checker = value;
}

Cell.prototype.setEmpty = function(value){
	this.empty = value;
}

Cell.prototype.setYellow = function(value){
	this.yellow = value;
}

Cell.prototype.setGreen = function(value){
	this.green = value;
}

Cell.prototype.setKing = function(value){
	this.king	= value;
}

Cell.prototype.clear = function(){
	this.value = CELL_WHITE;
	this.selected = false;
	this.movable = false;
	this.jumpable = false;
	this.king = false;
	this.yellow = false;
	this.green = false;
	this.checker = false;
	this.empty = true;
}

Cell.prototype.copyFrom = function(cell){
	this.value = cell.value;
	this.selected = false;
	this.movable = null;
	this.jumpable = null;
	this.king = cell.king;
	this.yellow = cell.yellow;
	this.green = cell.green;
	this.checker = cell.checker;
	this.empty = cell.empty;
	if(!this.king&&((this.y==7&&this.green)||(this.y==0&&this.yellow))){
		this.king = true;
		this.value++;
	}
}

Cell.prototype.renderView = function(){
	var img = document.createElement('img');        
	if(this.value!=CELL_BLACK){
		img.setAttribute("onclick", "click("+this.x+","+this.y+")");
		img.setAttribute("src", "client/images/checker-"+this.value+".png");
		img.setAttribute("id", this.x+"_"+this.y);
	}
	else{
		img.setAttribute("src", "client/images/checker-0.png");
	}
	if(this.selected){
		img.setAttribute("src", "client/images/checker-"+this.value+"-sel.png");
	}
	img.setAttribute("width", 33);
	img.setAttribute("height", 33);
	
	return img;
}

Cell.prototype.updateView = function(){
	if(this.value!=CELL_BLACK){
		document.images[this.x+"_"+this.y].src = "client/images/checker-"+this.value+".png";
	}
	if(this.selected){
		document.images[this.x+"_"+this.y].src = "client/images/checker-"+this.value+"-sel.png";
	}
}

Cell.prototype.effectBoom = function(){
	document.images[this.x+"_"+this.y].src = "client/images/checker-"+this.value+"-boom.gif";
}

Cell.prototype.effectAppear = function(){
	document.images[this.x+"_"+this.y].src = "client/images/checker-"+this.value+"-to.gif";
}
