UI.Interface =
{
	currentLocation: new Array,
	
	determineLocation: function(row,col)
	{
		var simpleRow = (row-(row%44))/44;
		var simpleCol = (col-(col%44))/44;
		
		if(simpleRow>6) simpleRow=6;
		if(simpleCol>6) simpleCol=6;
		
		return [simpleRow,simpleCol];
	},
	
	touchLocation: function(locX,locY)
	{
		var simpleX = (locX-(locX%44))/44;
		var simpleY = (locY-(locY%44))/44;
		
		if(simpleX>6) simpleX=6;
		if(simpleY>6) simpleY=6;
		
		return [simpleX,simpleY];
	},
	
	touchInit: function(row,col)
	{
		var th = UI.Interface;
		
		th.currentLocation = [row,col];
		th.touchMode=true;
		if(UI.Game.checkPiece(row,col)==true)
		{
			if(UI.Game.selectMode==true && row==UI.Game.selectInfo.row && col==UI.Game.selectInfo.col) UI.Game.selectMode=false;
			else th.updateDragObj(row,col,'tStart');
			
			var rObj =
			{
				rType: 'Interact',
				rMessage:
				{
					type:'click'
				},
				location: [row,col]
			};
			ClientData.currentGame.Report(rObj);
		}
		else if(UI.Game.selectMode==true && UI.Game.checkPiece(row,col)==false) th.updateDragObj(row,col,'tStart');
	},
	
	touchMove: function(row,col)
	{
		var th = UI.Interface;
		
		if(UI.Game.selectMode==true && th.touchMode==true)
		{
			th.currentLocation = [row,col];
			th.updateDragObj(row,col,'tMove');
		}
	},
	
	touchEnd: function()
	{
		var th = UI.Interface;
		
		var row = th.currentLocation[0];
		var col = th.currentLocation[1];
		th.touchMode=false;
		th.updateDragObj('tEnd');
		if(UI.Game.selectMode==true && (row!=UI.Game.selectInfo.row || col!=UI.Game.selectInfo.col) && UI.Game.checkPiece(row,col)!=true)
		{
			var rObj = new Object;
			rObj =
			{
				rType: 'Interact',
				rMessage:
				{
					type:'click'
				},
				location: th.currentLocation
			};
			
			return ClientData.currentGame.Report(rObj);
		}
	},
	
	updateDragObj: function(x,y,from)
	{
		var endDrag = function(obj){ obj.style.visibility = 'hidden'; };
		
		var moveDrag = function(x,y,obj)
		{
			var tempLoc = UI.Game.convertLocation(x,y);
			obj.style.webkitTransform = 'translate('+tempLoc[1]+'px,'+tempLoc[0]+'px) !important';
			if(obj.style.visibility=='hidden') obj.style.visibility = 'visible'; 
			
			if(UI.Game.boardRef[x][y]=='available') obj.style.opacity=1;
			else obj.style.opacity=.3;
		};
		
		
		if(from=='tMove' || from=='tStart') moveDrag(x,y,UI.Game.dragObj);
		else endDrag(UI.Game.dragObj);
	}
};