// JavaScript Document
intervallenMover 	= new Array();
intervallenBuilding = new Array();
function mover(id, to_x, to_y, to_width, to_height, speed, startMotion){
	clearTimeout(intervallenMover[id]);	
	
	if(!document.getElementById(id)){
		divElement 	= id;
		id = id.id;
	}else{
		divElement 	= document.getElementById(id);		
	}
	
	var intervalString = id + 'x' + to_x + 'x' + to_y + 'x' + to_width + 'x' + to_height + 'x' + speed;

	if(!startMotion){
		if(intervallenBuilding[id]){
			if(!to_x)		to_x 		= intervallenBuilding[id].to_x;
			if(!to_y)		to_y 		= intervallenBuilding[id].to_y;
			if(!to_width)	to_width 	= intervallenBuilding[id].to_width;
			if(!to_height)	to_height 	= intervallenBuilding[id].to_height;	
		}
		intervallenBuilding[id] = new Object();
		
		intervallenBuilding[id].intervalString	= intervalString;		
		intervallenBuilding[id].to_x			= to_x;
		intervallenBuilding[id].to_y 			= to_y;
		intervallenBuilding[id].to_width 		= to_width;
		intervallenBuilding[id].to_height 		= to_height;
		intervallenBuilding[id].speed 			= speed;
	
	}
	if(intervallenBuilding[id] != intervalString){
		to_x 		= intervallenBuilding[id].to_x;
		to_y 		= intervallenBuilding[id].to_y;
		to_width 	= intervallenBuilding[id].to_width;
		to_height 	= intervallenBuilding[id].to_height;
		speed 		= intervallenBuilding[id].speed; 
	}
	
	speed = (speed);
	if(speed < 1) speed = 1;
	if(speed > 40) speed = 40;	
	
	
	var notFinished = false;
	if(to_x){
		to_x 			= parseInt(to_x);		
		verschil 		= (to_x - parseInt(divElement.style.left));
		speed_x 		= verschil / speed;
		if(Math.abs(verschil) >= 1){
			if(speed_x < 1 && speed_x >= 0) speed_x = 1;
			if(speed_x > -1 && speed_x <= 0) speed_x = -1;				
			var new_x 		= parseInt(divElement.style.left) 		+ speed_x;
			notFinished 	= true;				
		}else{
			var new_x 		= to_x;
		}
		divElement.style.left 	= new_x + 'px';
		var to_x_to = '\''+to_x+'\'';
	}else{
		var to_x_to = 'false';
	}
	
	if(to_y){
		to_y 			= parseInt(to_y);	
		verschil 		= (to_y - parseInt(divElement.style.top));		
		speed_y 		= verschil / speed;
		if(Math.abs(verschil) >= 1){
			if(speed_y < 1 && speed_y >= 0) 	speed_y = 1;
			if(speed_y > -1 && speed_y <= 0) 	speed_y = -1;				
			var new_y		= parseInt(divElement.style.top) + speed_y;
			notFinished 	= true;				
		}else{
			var new_y 		= to_y;
		}
		divElement.style.top 	= new_y + 'px';
		var to_y_to = '\''+to_y+'\'';
	}else{
		var to_y_to = 'false';
	}
	
	if(to_width){
		to_width 		= parseInt(to_width);						
		if(divElement.style.width == 'auto'){
			divElement.style.width = divElement.offsetWidth + 'px';
		}		
		verschil 		= (to_width - parseInt(divElement.style.width));				
		speed_width 		= (to_width - parseInt(divElement.style.width)) 			/ speed;
		if(Math.abs(verschil) >= 1){
			if(speed_width < 1 && speed_width >= 0) speed_width = 1;
			if(speed_width > -1 && speed_width <= 0) speed_width = -1;			
			var new_width 		= parseInt(divElement.style.width) 		+ speed_width;
			notFinished 		= true;				
		}else{
			var new_width 		= to_width;
		}
		divElement.style.width 	= new_width + 'px';
		var to_width_to = '\''+to_width+'\'';
	}else{
		var to_width_to = 'false';
	}
	
	
	if(to_height){
		to_height 				= parseInt(to_height);						
	
		if(divElement.style.height == 'auto'){
			divElement.style.height = divElement.offsetHeight + 'px';
		}
	
		verschil				= (to_height - parseInt(divElement.style.height));
		speed_height 			= ((to_height - parseInt(divElement.style.height)) 			/ speed);
	
		if(Math.abs(verschil) >= 1){
			if(speed_height < 1 && speed_height >= 0) speed_height = 1;
			if(speed_height > -1 && speed_height <= 0) speed_height = -1;				
			var new_height 		= parseInt(divElement.style.height) 		+ speed_height;
			notFinished 		= true;				
		}else{
			var new_height 		= to_height;
		}
		divElement.style.height 	= new_height + 'px';
		var to_height_to = '\''+to_height+'\'';
	}else{
		var to_height_to = 'false';
	}
	
	
							
	if(notFinished == true){
		var exec = 'mover(\''+id+'\','+to_x_to+','+to_y_to+','+to_width_to+','+to_height_to+','+speed+',true)';
		intervallenMover[id] = setTimeout(exec,30);
	}
	
}	

