function Card(myId,x,y,color,mine)
{
	var self = this;
	this.myId = myId;
	this.color = color? color:"yellow";
	this.mine = mine? true:false;
	
	this.x = x;
	this.y = y;
	
	this.id = base.getId();
	
	this.div = this.addCard(x,y,this.mine);
	this.moving = false;
	this.editing = false;
	
	this.div.onmouseover = function(e)
	{
		this.style.cursor = "pointer";
	}
	
	this.div.onclick = function()
	{
		self.divOnclick(self);
	}

	this.div.onmousedown = function(e)
	{
		self.divMousedown(e,self,this);
		return false;
	}
	

	
	this.div.onmouseup = function()
	{
		this.style.opacity = 1;
		base.removeDragCard(self.id);
	}
	
	this.div.onmouseout = function()
	{
		this.style.opacity = 1;
		//base.removeDragCard(self.id);
	}
		
	this.div.oncontextmenu = function(e)
	{
		base.removeDragCard(self.id);
		base.rightmenu.displayMenu(self,e);
	}
	
}


Card.prototype.divOnclick = function(root)
{
	var self = root;
	if(self.mine)
	{
		if(!self.editing)
		{
			//debug.changeValue(self.moving);
			if(!self.moving)
			{
				self.editing = true;
				self.thisDiv = this;
				self.editCard();
				self.div.onclick = false;
				self.div.onmousedown = false;
			}else
			{
				self.moving = false;
			}
		}
	}
}

Card.prototype.divMousedown = function(e,root,div)
{
	var self = root;
	
	if(self.mine)
	{
		if(!isMSIE)
		{
			div.style.opacity = 0.4;
		
			div.offsetX = div.style.left.match(/[0-9]*/) - e.pageX;
			div.offsetY = div.style.top.match(/[0-9]*/) - e.pageY;
		
			base.setDragCard(self.id);
		}else
		{
			div.offsetX = div.style.left.match(/[0-9]*/) - event.clientX;
			div.offsetY = div.style.top.match(/[0-9]*/) - event.clientY;
			
			base.setDragCard(self.id);
		}
	}
}
	
Card.prototype.editCard = function()
{

	var self = this;
	
	var div = this.div;
	var pre = div.getElementsByTagName("pre")[0];
	
	var input = document.createElement("textarea");
	input.style.width = 200;
	input.style.height = 80;
	
	var old = pre.childNodes[0].nodeValue;
	
	if(old)
	{
		if(!old.match(/^#/)) input.value = old;
	}
	
	input.setAttribute("type","text");
	pre.innerHTML = "";
	pre.appendChild(input);
	input.focus();

	input.onblur = function()
	{
		if(this.value)
		{
			var text = document.createTextNode(this.value.striptags());
			div.setAttribute("title","editDate:" + new Date());
		}else
		{
			var text = document.createTextNode(old);
		}
		
		
		pre.appendChild(text);
		div.appendChild(pre);
		pre.removeChild(input);
		self.editing = false;
		self.div.onclick = function()
		{
			self.divOnclick(self);
		}
		
		self.div.onmousedown = function(e)
		{
			self.divMousedown(e,self,this);
			return false;
		}
		
		
	}

}

Card.prototype.addCard = function(x,y,mine)
{
	var div = document.createElement("div");
	var img = document.createElement("img");
	img.style.display = "none";
	
	div.setAttribute("id","card_id_is_" + this.id);
	div.setAttribute("title","addDate:" + new Date());
	var txt = document.createTextNode("#" + this.id);
	var pre = document.createElement("pre");
	pre.appendChild(txt);
	div.appendChild(pre);
	div.appendChild(img);
	
	div.img = img;
	
	if(mine)
	{
		div.className = "card " + this.color + " mine";
	}else
	{
		div.className = "card " + this.color;
	}
	div.color = this.color;
	div.style.left = x;
	div.style.top = y;
	return div;
}

Card.prototype.changeValue = function(str)
{
	var s = str.split("____").join("\n");
	this.div.getElementsByTagName("pre")[0].childNodes[0].nodeValue = s.striptags();
}

Card.prototype.changeImage = function(str)
{
	this.div.img.style.display = "block";
	this.div.img.setAttribute("src",str);
}

Card.prototype.changeDate = function(date)
{
	this.div.setAttribute("title",date);
}

String.prototype.striptags = function()
{
	return this.replace(/<.*?>/g,"").replace(/'/g,"").replace(/"/g,"");
}