// this file adds, cursor handling to FV cursor handling:

freevolution.prototype.extend(
	{
		movecursortotile:function(x,y){
			// tile should be the image object
			this.cursorover['x']=x
			this.cursorover['y']=y;
			// better But the cursor tile now blocks the two tiles above from receiving onmouseover events, so the cursor tile also need out of bounds checks.
			if( this.planes[x] && this.planes[x][y] && this.planes[x][y][0]){ // check to see if we need to add the upper cursor	
				this.cursor.src="../tilegen/cursor/0-0-0-0.png";
				this.cursor.style.top=this.planes[x][y][0][3].style.top;
				this.cursor.style.left=this.planes[x][y][0][3].style.left;
				if(this.quality!='low'){
					this.watercursor.style.zIndex==this.tiles[x][y][2].style.zIndex;
					this.watercursor.style.display='block';
					this.watercursor.style.top=this.tiles[x][y][2].style.top;
					this.watercursor.style.left=this.tiles[x][y][2].style.left;
					this.watercursor.src="../tilegen/cursor/"+this.tiles[x][y][2].src.match(/\d\-\d\-\d\-\d/)+'.png';
				}
			} else {
				this.watercursor.style.display='none';
				this.cursor.style.top=this.tiles[x][y][2].style.top;
				this.cursor.style.left=this.tiles[x][y][2].style.left;
				this.cursor.src="../tilegen/cursor/"+this.tiles[x][y][2].src.match(/\d\-\d\-\d\-\d/)+'.png';
			}
			if(this.check_cursor==false){
				window.setTimeout(this.enableCheckCursor.bind(this),200);
			}
			return true;
		},
		
		enableCheckCursor:function(){
			this.check_cursor=true;
		},
		
		checkcursor:function(event) {
			if (!event) var event = window.event; // make sure we actually get the event in IE
			// If we call this function, the user is waving the mouse over the cursor
			// If out of bounds, move the cursor to the next tile
			var aMove = checkbounds(this.cursor,event);
			if(aMove != false){
				if(this.check_cursor==true) {
					this.check_cursor=false; // disable any moves the following milliseconds, (untill this move is actually completed)
					this.dragStop(); // remove any dragging
					this.movecursor(aMove[0],aMove[1]);
					return true;
				}
			} else {
				return false;
			}
		},
			
		movecursor:function(deltaX,deltaY){
			// Figure out where the cursor is, and move it by x and y
			// Bah..  someone labelled the tiles as "y-x", oops sorry, (got messed up because of all the axis involved in the isometric stuff i guess.)
	
			var x = parseInt(this.cursorover['x']) + parseInt(deltaY);
			var y = parseInt(this.cursorover['y']) + parseInt(deltaX);
			
			if(this.tiles[x] && this.tiles[x][y]){
				this.movecursortotile(x,y);
			} else {
				this.check_cursor=true;
			}
		}
	}
); 
