//**These are the x co-ordinates of the vertical lines.  These are got by
//**trial and error!
VLINE=	new Array(6)
VLINE[0]=	0
VLINE[1]=	58
VLINE[2]=	122
VLINE[3]=	190
VLINE[4]=	440
VLINE[5]=	7000

//**These are the y co-ordinates of the vertical lines.  These too are got by
//**trial and error.
HLINE=	new Array(6)
HLINE[0]=	0
HLINE[1]=	51
HLINE[2]=	120
HLINE[3]=	192
HLINE[4]=	280
HLINE[5]=	7000


function gridMoveObject(	id,
				X, 
				Y, 
				track){



	this.base=movingObject
	
	this.track=track	//whether the box is running horizontally or vertically

	this.VLINEL=0

	this.HLINET=0

	this.base(X,Y, gridMove, id)

	this.setz=SetZIndx

}

gridMoveObject.prototype=new movingObject

function gridMoveObjectContainer(	id,
				objID, 
				X, 
				Y, 
				track){
	
	this.base=gridMoveObject
	this.objShow=0
	this.objID=objID	//the id of the object associated with the box

	this.base(id,X,Y, track)


}

gridMoveObjectContainer.prototype=new gridMoveObject



function gridMove(){
	
	var moving=CurrentMovingObject.moving

	//** moving=1 allows movement, moving=0 stops it	

	if (moving==1)
	{
   		moveByX=event.x-CurrentMovingObject.offX

		if(moveByX<1)
			moveByX=0

		moveByY=event.y-CurrentMovingObject.offY
	
		if(moveByY<1)
			moveByY=0

	if (CurrentMovingObject.track=="H")
	{
	
	//** whichVLine helps keep track of the vertical lines
	//** (event.x>lastx) means the object is moving to the right
	//** so look for event when vertical line to the right is met

		if(event.x>CurrentMovingObject.X)
			VLINECHK=VLINE[CurrentMovingObject.VLINEL+1]
		else
			VLINECHK=VLINE[CurrentMovingObject.VLINEL]

		if(((CurrentMovingObject.X+CurrentMovingObject.goX<VLINECHK-1)|(CurrentMovingObject.X+CurrentMovingObject.goX>VLINECHK+1)))
		{
			CurrentMovingObject.X=(moveByX)
		}
		else if(Math.abs(event.x-CurrentMovingObject.X)<=Math.abs(event.y-CurrentMovingObject.Y))
		{
			CurrentMovingObject.Y=(moveByY)		
			CurrentMovingObject.track="V"
		}		
		else
		{
			CurrentMovingObject.X=(moveByX)
		}
	}
	else if (CurrentMovingObject.track=="V")
	{
		if(event.y>CurrentMovingObject.Y)
			HLINECHK=HLINE[CurrentMovingObject.HLINET+1]
		else
			HLINECHK=HLINE[CurrentMovingObject.HLINET]

		if(((CurrentMovingObject.Y+CurrentMovingObject.goY<HLINECHK-1)|(CurrentMovingObject.Y+CurrentMovingObject.goY>HLINECHK+1)))
		{	
			CurrentMovingObject.Y=(moveByY)	
		}
		else if(Math.abs(event.x-CurrentMovingObject.X)>=Math.abs(event.y-CurrentMovingObject.Y))
		{			
			CurrentMovingObject.X=(moveByX)	
			CurrentMovingObject.track="H"
		}		
		else
		{
			CurrentMovingObject.Y=(moveByY)			
		}
	}

	paintObj(CurrentMovingObject)

//**this bit checks what two vertical gridlines are either side of object

if(CurrentMovingObject.X+CurrentMovingObject.goX>VLINE[CurrentMovingObject.VLINEL+1])
	CurrentMovingObject.VLINEL++
else if(CurrentMovingObject.X+CurrentMovingObject.goX<VLINE[CurrentMovingObject.VLINEL])
	CurrentMovingObject.VLINEL--

//**this bit checks what two horizontal gridlines are either side of object
if(CurrentMovingObject.Y+CurrentMovingObject.goY>HLINE[CurrentMovingObject.HLINET+1])
	CurrentMovingObject.HLINET++
else if(CurrentMovingObject.Y+CurrentMovingObject.goY<HLINE[CurrentMovingObject.HLINET])
	CurrentMovingObject.HLINET--


}//if moving


}
