function clip_layer(layer_name,x1,y1,width,height) {
// point (x,y) = location of the origin of the new clipping rectangle
// width and height of the clipping rectangle
// rect(10px 500px 50px 20px)
	x2 = x1+width;
	y2 = y1+height;
	document.getElementById( layer_name ).style.clip = "rect("+y1+"px "+x2+"px "+y2+"px "+x1+"px)";
}

// layer object
function layer_obj (order_num,obj_name,layer_title_name,layer_name) {
	this.order_num = order_num;
	this.obj_name = obj_name;
	this.layer_title_name = layer_title_name;
	this.layer_name = layer_name;
	this.asleep = 1;
	this.pos_title_x = position_x_of_layer(layer_title_name);
	this.pos_title_y = position_y_of_layer(layer_title_name);
	this.pos_x = position_x_of_layer(layer_name);
	this.pos_y = position_y_of_layer(layer_name);
	this.anim_init = anim_init;
	this.anim_select = anim_select;
	this.back_select = back_select;
	this.init = init;
	this.speed = 10;
	this.timeout = 10;
}

function init() {
	// layer title
	hide_layer(this.layer_title_name);
	move_layer_y(this.layer_title_name,0);
	this.anim_init();
	
	// layer para
	move_layer_y(this.layer_name,-1000);
	hide_layer(this.layer_name);
	
}


function anim_select() {
	y_from = position_y_of_layer(this.layer_title_name);
	delta_y = (50 - 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_title_name,y_from + delta_y);
	
	if (Math.abs(delta_y)>=1) {
		setTimeout(this.obj_name+".anim_select()",this.timeout);
	} else {
		move_layer_y(this.layer_name,position_y_of_layer(this.layer_title_name));
		hide_layer(this.layer_title_name);
		show_layer(this.layer_name);
		if (document.forms["form_"+this.layer_name]) {
			document.forms["form_"+this.layer_name].submit();
		}
	}
}

function anim_init() {
	y_from = position_y_of_layer(this.layer_title_name);
	
	delta_y = 6;
	y = y_from + delta_y;
	move_layer_y(this.layer_title_name,y);
	
	if (y_from + delta_y>-20+this.pos_title_y) {
		show_layer(this.layer_title_name);
	}
	
	//if (Math.abs(delta_y)>=1) {
	if (y<this.pos_title_y) {
		setTimeout(this.obj_name+".anim_init()",this.timeout);
	} else {
		move_layer_y(this.layer_title_name,this.pos_title_y);
		// flag pour anim suivante : array [anim1, anim2, ...]
	}
}

function back_select() {
	y_from = position_y_of_layer(this.layer_title_name);
	delta_y = 5;
	
	move_layer_y(this.layer_title_name,y_from + delta_y);
	
	//if (Math.abs(delta_y)>=1) {
	if (y_from + delta_y<this.pos_title_y) {
		setTimeout(this.obj_name+".back_select()",this.timeout);
	} else {
		// flag pour anim suivante : array [anim1, anim2, ...]
	}
}


/*
function wipe_down(height) {
	clip_layer(this.layer_name,this.pos_x,this.pos_y,this.width,height);
	alert(height + this.speed);
	alert(this.height);
	if ( height + this.speed < this.height) {
		height = height + this.speed;
		alert(this.obj_name + ".wipe_down(" + height + ")");
		setTimeout( this.obj_name + ".wipe_down(" + height + ")",this.timeout);
	}
}

function wipe_up(height) {
	clip_layer(this.layer_name,this.pos_x,this.pos_y,this.width,height);
	height = height - this.speed;
	if ( height < 0 ) {
		clip_layer(this.layer_name,this.pos_x,this.pos_y,this.width,0);
	} else {	
		setTimeout( this.obj_name + ".wipe_up(" + height + ")",this.timeout);
	}
}
*/
