

/* 
 * this function moves a picture
 * stepx 	= step in pixel on x-axis
 * stepy 	= step in pixel on y-axis
 * startx 	= start position (x-axis)
 * starty 	= start position (y-axis)
 * endx 	= end position (x-axis)
 * endy 	= end position (y-axis)
 * timeout 	= timeout of animation here you canchange the speed... smaller value means more speed
 * loop 	= should the animation run in a loop (1 = YES, 0 = NO)
 */
function move (stepx, stepy, startx, starty, endx, endy, timeout, loop)
{
//-------------------------------------- VERTIAL --------------------------------------
		// from top to bottom
		if (startx == endx && starty > endy)
		{
			// to move it from the top to the bottom we need a positive step
			if (stepy < 0)
			{
				stepy = stepy * -1;
			}
			doVerticalMove(stepx, stepy, startx, starty, endx, endy, timeout, loop);
		}
		// from bottom to top
		if (startx == endx && starty < endy)
		{
			// to move it from the bottom to the top we need a negative step
			if (stepy > 0)
			{
				stepy  = stepy * -1;
			} // end if (stepy > 0)
			doVerticalMove(stepx, stepy, startx, starty, endx, endy, timeout, loop);
		} // end if (startx == endx && starty < endy)
				
//-------------------------------------- HORIZONTAL --------------------------------------		
		// from left to right
		if (starty == endy && startx > endx)
		{
			if (stepx < 0)
			{
				stepx = stepx * -1;
			} // end if (stepx < 0)
			doHorizontalMove(stepx, stepy, startx, starty, endx, endy, timeout, loop);
		} // end if (starty == endy && startx > endx)
		
		// from right to left
		if (starty == endy && startx < endx)
		{
			{
				stepx = stepx * -1;
			} // end if (stepx < 0)
			doHorizontalMove(stepx, stepy, startx, starty, endx, endy, timeout, loop);
		} // end if (starty == endy && startx > endx)
	
// -------------------------------------- DIAGONAL --------------------------------------
		if (startx != endx && starty != endy)
		{
			if (stepx == undefined || stepx == 9999)
			{
				if (startx == 0 || starty == 0)
				{
					stepx = (endx-startx) / (endy - starty) * stepy;
				}
				else
				{
					stepx = startx * stepy / starty;
				}
			}
			if (stepy == undefined || stepy == 9999)
			{
				if (startx == 0 || starty == 0)
				{
					stepy = (endy - starty) / (endx - endy) * stepx;
				}
				else
				{
					stepy = starty * stepx / startx;
				}
			}
			// if startx > end< and stepx > 0 we have to change to "-" because stepx has to be be a "-*" value
			if (startx > endx && stepx > 0 ) 
			{
				stepx = stepx * -1;
			}// end if (startx > endy && stepx > 0)
			
			// if startx < endx and stepx < 0 whe have to change to + because stepx has to be a "+*" value
			if (startx < endx && stepx < 0)
			{
				stepx = stepx * -1;
			} // end if (startx < endx && stepx < 0)
			
			// if starty > endy and stepy > 0 we have to change to "-" because stepy has to be be a "-*" value
			if (starty > endy && stepy > 0) 
			{
				stepy = stepy * -1;
			}
			// if starty < endy and stepy < 0 we have to change to "+" because stepy has to be be a "+*" value
			if (starty < endy && stepy < 0)
			{
				stepy = stepy * -1;
			}
			doDiagonalMove(stepx, stepy, startx, starty, endx, endy, timeout, loop);

		} // end if (startx <> endx && starty <> endy			
		
		
} // end function move




// -------------------------------------- VERTIAL --------------------------------------
/* this is a private function and should not be called from any website directly */
function doVerticalMove(stepx, stepy, startx, starty, endx, endy, timeout, loop) 
{
		var y = document.getElementById('fahrt').offsetTop;
		var stop = 0;
			
		// starty > endy means we move it from bottom to top
		if (starty > endy)
		{
			if ( y >= -1 * endy )
			{
				stepy = -1 * stepy;
				if (loop == 0)
				{
					stop = 1;
				} // end if (loop == 0)
			} // end if (y > -1 * endy)	
		} // end if (starty > endy)
		// else will move picture from top to bottom
		else
		{
			if ( y <= -1 * endy )
			{
				stepy = -1 * stepy;
				if (loop == 0)
				{
					stop = 1;
				} // end if (loop == 0)
			} // end if (y < -1 * endy)
		}// end else

		y = y + stepy;
		if (stop == 0)
		{
			document.getElementById('fahrt').style.top = y + "px";
			setTimeout("doVerticalMove("+ stepx + "," + stepy + "," + startx + "," + starty + "," + endx + "," + endy + "," + timeout + "," + loop + ")",timeout);
		} // end if (stop == 0)
} // end function doVerticalMove


//-------------------------------------- HORIZONTAL --------------------------------------
/* this is a private function and should not be called from any website directly */
function doHorizontalMove(stepx, stepy, startx, starty, endx, endy, timeout, loop)
{
	var x = document.getElementById('fahrt').offsetLeft;
	var stop = 0;
		
	// startx > endx means we move it from left to right
	if (startx > endx)
	{
		if ( x >= -1 * endx )
		{
			stepx = -1 * stepx;
			if (loop == 0)
			{
				stop = 1;
			} // end if (loop == 0)
		} // end if (x > -1 * endy)	
	} // end if (startx > endx)
	// else will move picture from right to left
	else
	{
		if ( x <= -1 * endx )
		{
			stepx = -1 * stepx;
			if (loop == 0)
			{
				stop = 1;
			} // end if (loop == 0)
		} // end if (y < -1 * endy)
	}// end else

	x = x + stepx;	
	if (stop == 0)
	{
		document.getElementById('fahrt').style.left = x + "px";
		setTimeout("doHorizontalMove("+ stepx + "," + stepy + "," + startx + "," + starty + "," + endx + "," + endy + "," + timeout + "," + loop + ")",timeout);
	} // end if (stop == 0)
} // end function doHorizontalMove


//-------------------------------------- DIAGONAL --------------------------------------
/* this is a private function and should not be called from any website directly */
function doDiagonalMove(stepx, stepy, startx, starty, endx, endy, timeout, loop, posx, posy)
{
	var stop = 0;
	if (posx == undefined)
	{
		posx = document.getElementById('fahrt').offsetLeft;
	} // end if (posx == undefined)
	if (posy == undefined)
	{
		posy = document.getElementById('fahrt').offsetTop;
	} // end if (posy == undefined)
	
	
	// from top right to bottom left
	if (startx < endx && starty > endy)
	{
		if ( (endx * -1) >= posx || (endy * -1) <= posy )
		{
			stepx=-1 * stepx;
			stepy=-1 * stepy;
			posx = endx * -1;
			posy = endy * -1;
			if (loop == 0)
			{
				stop = 1;
			}
		} // end if ( (endx * -1) >= posx || (endy * -1) <= posy )
	
		if ( (startx * -1) <= posx || (starty * -1) >= posy)
		{
			stepx=-1 * stepx;
			stepy=-1 * stepy;
			posx = startx * -1;
			posy = starty * -1;
		} // end if ( (startx * -1) <= posx || (starty * -1) >= posy)
	} // end if (startx < endx && starty > endy)
	
	// from bottom right to top left
	
	if (startx < endx && starty < endy)
	{
		if ( (endx * -1) >= posx || (endy * -1) >= posy )
		{
			stepx=-1 * stepx;
			stepy=-1 * stepy;
			posx = endx * -1;
			posy = endy * -1;
			if (loop == 0)
			{
				stop = 1;
			}
		} // end if ( (endx * -1) >= posx || (endy * -1) <= posy )
	
		if ( (startx * -1) <= posx || (starty * -1) <= posy)
		{
			stepx=-1 * stepx;
			stepy=-1 * stepy;
			posx = startx * -1;
			posy = starty * -1;
		} // end if ( (startx * -1) <= posx || (starty * -1) >= posy)		
	} // end if (startx > endx && starty < endy) 
	
	
	// from top left to bottom right
	if (startx > endx && starty > endy)
	{
		
		if ( (endx * -1) <= posx || (endy * -1) <= posy )
		{
			stepx=-1 * stepx;
			stepy=-1 * stepy;
			posx = endx * -1;
			posy = endy * -1;
			if (loop == 0)
			{
				stop = 1;
			}
		} // end if ( (endx * -1) >= posx || (endy * -1) <= posy )
	
		if ( (startx * -1) >= posx || (starty * -1) >= posy)
		{
			stepx=-1 * stepx;
			stepy=-1 * stepy;
			posx = startx * -1;
			posy = starty * -1;
		} // end if ( (startx * -1) <= posx || (starty * -1) >= posy)
	} // end if (startx < endx && starty > endy)
	
	
	
	posx += stepx;
	posy += stepy;
	if (stop == 0)
	{
		document.getElementById('fahrt').style.left = posx + "px";
		document.getElementById('fahrt').style.top = posy + "px";
		setTimeout("doDiagonalMove("+ stepx + "," + stepy + "," + startx + "," + starty + "," + endx + "," + endy + "," + timeout + "," + loop + "," + posx + "," + posy + ")",timeout);
	}
	
} // end function doDiagonalMove
function test()
{
if (movement == "drl")
{
	var x = document.getElementById('fahrt').offsetLeft;
	var y = document.getElementById('fahrt').offsetTop;
	if ( (x >= startx || y >= starty))
	{
		alert ("Ich wechsle X ist: " + x + " startx ist " + startx + " y ist: " + y + " starty ist: " + starty);
		stepx=-1 * stepx;
		stepy=-1 * stepy;
	} // end if
	
	if ( (x <= -1 *endx || y <= -1 * endy))
	{
		alert ("Ich wechsle X ist: " + x + " endx ist " + endx + " y ist: " + y + " endy ist: " + endy);
		stepx=-1 * stepx;
		stepy=-1 * stepy;
	} // end if
	
	x+=stepx;
	y+=stepy;
	document.getElementById('fahrt').style.left = x + "px";
	document.getElementById('fahrt').style.top = y + "px";
	setTimeout("doMove("+ stepx + "," + stepy + "," + startx + "," + starty + "," + endx + "," + endy + ",'" + movement + "'," + timeout + "," + loop + ")",timeout);
} // end diagonal drl


if (movement == "dlr")
{
	var x = document.getElementById('fahrt').offsetLeft;
	var y = document.getElementById('fahrt').offsetTop;
	

	if ( (endx * -1) >= x || (endy * -1) <= y )
	{
		stepx=-1 * stepx;
		stepy=-1 * stepy;
		this.posx = endx * -1;
		this.posy = endy * -1;
	}
	
	if ( (startx * -1) <= x || (starty * -1) >= y)
	{
		stepx=-1 * stepx;
		stepy=-1 * stepy;
		this.posx = startx * -1;
		this.posy = starty * -1;
	}

	this.posx += stepx;
	this.posy += stepy;
	document.getElementById('fahrt').style.left = this.posx + "px";
	document.getElementById('fahrt').style.top = this.posy + "px";
	setTimeout("doMove("+ stepx + "," + stepy + "," + startx + "," + starty + "," + endx + "," + endy + ",'" + movement + "'," + timeout + "," + loop + ")",timeout);
} // end diagonal drl

}
