var dragObject=0;
var mousePos=0;
dragTile= new Object()
dragTile.flag=false;
dragTile.wrong=false;
var tile=0;
var trad=null;
var eng=null;
function Tile(idright) {
this.id="tdr"+idright;
this.getid = getid;
this.fix=false;
this.getfix=getfix;
this.setfix=setfix;
	} 
	function getid()
  {
    return this.id;
  }
	function getfix()
  {
    return this.fix;
  }
    function setfix(fix)
  {
	  this.fix=fix;
  }

	function reveal(valleft,idleft){
		if (dragTile.style.visibility=="visible"){
			prm="td"+idleft;
	if (dragTile.innerHTML==valleft){
document.getElementById(prm).style.visibility="hidden"
document.getElementById(tile).style.visibility="hidden"
dragTile.style.visibility="hidden"
}else{
dragTile.wrong=true
dragTile.style.visibility="hidden"
document.getElementById(myTile.getid()).innerHTML=eng + " = " + trad 
eng=null
trad=null
}
}
	}
function pickpic(engright,valright,idright){
eng=engright
trad=valright
myTile=new Tile(idright)
if (!dragTile.flag){
dragTile=document.getElementById("imag");
dragTile.style.visibility="visible"
dragTile.style.backgroundColor="papayawhip"
dragTile.style.position="absolute"
dragTile.style.left=mousePos.x - 2 + "px";
dragTile.style.top=mousePos.y +2 + "px";
dragTile.innerHTML=document.getElementById(myTile.getid()).innerHTML
document.getElementById(myTile.getid()).innerHTML=""
document.getElementById(myTile.getid()).style.backgroundColor="gray"
tile=myTile.getid()
}
dragTile.flag=true
	} 
//..............finds coordinates.....................//
	function catchit(){
document.onmousemove = mouseMove;
document.onmouseup = mouseUp;
}
function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
	x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
	y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	
	};
	};

function mouseMove(ev){

		ev           = ev || window.event;
		mousePos = mouseCoords(ev);
if (dragTile.flag==true){
dragTile.style.left=mousePos.x-2 + "px";
dragTile.style.top=mousePos.y +2 + "px";
}
}
function mouseUp(ev){
	if (dragTile.flag){
dragTile.style.visibility="hidden";
if (!dragTile.wrong){
document.getElementById(tile).style.backgroundColor="papayawhip";
document.getElementById(tile).innerHTML=dragTile.innerHTML
}else{
document.getElementById(tile).style.backgroundColor="gray";
dragTile.wrong=false	
}
}
	dragTile.flag=false;
}
function hlght(id){
	id="td"+id
	document.getElementById(id).style.backgroundColor="lawngreen";
}
function hlghtout(id){
	id="td"+id
	document.getElementById(id).style.backgroundColor="tan";
}
function expl(){
	alert("Mutati cate un patratel din dreapta in stanga, potrivit traducerii. Cand patratul din stanga se coloreaza in verde, dati drumul la patratel.")
}
