
// layer object
function layer_show_image_obj (obj_name,layer_name) {
	this.obj_name = obj_name;
	this.layer_name = layer_name;
	this.asleep = 1;
	this.pos_x = position_x_of_layer(layer_name);
	this.pos_y = position_y_of_layer(layer_name);
	this.init_x = init_x;
	this.init2_x = init2_x;
	this.init_y = init_y;
	this.init = init;
	this.speed = 10;
	this.timeout = 10;
	this.x_to = this.pos_x;
	this.y_to = this.pos_y;
}




function init_x(new_x_to) {
	this.x_to = new_x_to;
	this.init2_x();
}
function init2_x() {
	x_from = position_x_of_layer(this.layer_name);
	
	delta_x = (this.x_to - x_from)/this.speed;
	
	if (Math.abs(delta_x)!=0) {
		delta_x = (2*(delta_x>0) - 1) * Math.max(Math.abs(delta_x),1);
	}
	
	move_layer_x( this.layer_name , x_from + delta_x );
	
	if (Math.abs(delta_x)>=1) {
		setTimeout(this.obj_name+".init2_x()",this.timeout);
	} else {
		move_layer_x(this.layer_name,this.x_to);
	}
}



function init_y(new_y_to) {
	this.y_to = new_y_to;
	this.init2_y();
}
function init2_y() {
	y_from = position_y_of_layer(this.layer_name);
	
	delta_y = (this.y_to - y_from)/this.speed;
	
	if (Math.abs(delta_y)!=0) {
		delta_y = (2*(delta_y>0) - 1) * Math.max(Math.abs(delta_y),1);
	}
	
	move_layer_y( this.layer_name , y_from + delta_y );
	
	if (Math.abs(delta_y)>=1) {
		setTimeout(this.obj_name+".init_y()",this.timeout);
	} else {
		move_layer_y(this.layer_name,this.y_to);
	}
}



function init(x_to,y_to) {
	this.init_x(x_to);
	this.init_y(y_to);
}
