/***********************************************************************
*                                                                      *
*  Realise par Le Point Com - David Affagard                           *
*                                                                      *
*  La recuperation et l'exploitation de ce code est autorisee          *
*                                                                      *
*  avec la mention des auteurs                                         *
*                                                                      *
*                                                                      *
************************************************************************/

function obj_layer (obj_name,layer_name) {
	
	this.obj_name = obj_name;
	this.layer_name = layer_name;
	
	this.x = 0;
	this.y = 0;
	this.x_ini = 0;
	this.y_ini = 0;
	this.x_to = 0;
	this.y_to = 0;
	
	this.speed = 6;
	this.timeout = 30;
	
	this.opacity = 0;
	this.opacity_timeout = 100;
	if (browse_no_opacity) {
		this.opacity_step = 0;
		this.opacity_max = 0;
	} else if (browse_filter) {
		this.opacity_step = 20;
		this.opacity_max = 100;
	} else {
		this.opacity_step = 0.20;
		this.opacity_max = 1;
   }
	
	this.hide = hide;
	this.show = show;
	this.show_display = show_display;
	this.hide_display = hide_display;
	this.move_x = move_x;
	this.move_y = move_y;
	this.move_xy = move_xy;
	this.move_to_x = move_to_x;
	this.move_to_y = move_to_y;
	this.move_to_xy = move_to_xy;
	this.get_pos_x = get_pos_x;
	this.get_pos_y = get_pos_y;
	this.init_move = init_move;
	this.launch_init_move = launch_init_move;
	
	this.set_layer_opacity = set_layer_opacity;
	this.fade_in = fade_in;
	this.fade_out = fade_out;
	
	this.setTimeout = '';
	
	this.busy = 0;
	

}

function get_pos_x() {
	this.x = document.getElementById(this.layer_name).offsetLeft;
}
function get_pos_y() {
	this.y = document.getElementById(this.layer_name).offsetTop ;
}
function hide() {
	document.getElementById( this.layer_name ).style.visibility= "hidden";
}

function show() {
	document.getElementById( this.layer_name ).style.visibility= "visible";
}

function show_display() {
	document.getElementById( this.layer_name ).style.display = "block";
}

function hide_display() {
	document.getElementById( this.layer_name ).style.display = "none";
}


function move_x() {
	document.getElementById( this.layer_name ).style.left = this.x+"px";
}
function move_y() {
	document.getElementById( this.layer_name ).style.top = this.y+"px";
}
function move_xy() {
	this.move_x();
	this.move_y();
}


function move_to_x (){
	this.get_pos_x();
	with ( Math ) {
		if (abs(this.x_to - this.x)<this.speed && this.x_to != this.x) {
			delta_x = (this.x_to - this.x)/abs(this.x_to - this.x);
		} else {
			delta_x = floor(( this.x_to - this.x )/this.speed);
		}
		abs_delta_x = abs(delta_x);
	}
	if ( abs_delta_x > 0 ) {
		this.x += delta_x;
		this.move_x();
		setTimeout( this.obj_name+'.move_to_x();',this.timeout );
		this.busy = 1;
	} else {
		this.x = this.x_to;
		this.move_x();
		this.busy = 0;
	}
}

function move_to_y (){
	this.get_pos_y();
	with ( Math ) {
		if (abs(this.y_to - this.y)<this.speed && this.y_to != this.y) {
			delta_y = (this.y_to - this.y)/abs(this.y_to - this.y);
		} else {
			delta_y = floor(( this.y_to - this.y )/this.speed);
		}
		abs_delta_y = abs(delta_y);
	}
	if ( abs_delta_y > 0 ) {
		this.y += delta_y;
		this.move_y();
		setTimeout( this.obj_name+'.move_to_y();',this.timeout );
	} else {
		this.y = this.y_to;
		this.move_y();
	}
}


function move_to_xy() {
	this.show();
	this.move_to_x();
	this.move_to_y();
}

function init_move() {
	this.move_to_xy();
	// setTimeout(this.obj_name+".move_to_xy();",100);
	setTimeout(this.obj_name+".launch_init_move();",2000);
}

function launch_init_move() {
	this.hide();
	this.x = this.x_ini;
	this.y = this.y_ini;
	this.move_xy();
	this.show();
	// alert (this.obj_name +" "+ this.x);
	setTimeout(this.obj_name+".init_move();",3000);
}

function fade_out(){
	// alert(this.opacity);
	if (this.opacity > 0){
		//alert(this.opacity-this.opacity_step);
		this.opacity = Math.max(this.opacity-this.opacity_step,0);
		this.set_layer_opacity();
		this.busy = 1;
		setTimeout(this.obj_name+'.fade_out();',this.opacity_timeout);
		// speed en dur = 100 pour compatibilitŽ IE.
	} else {
		this.opacity = 0;
		this.set_layer_opacity();
		this.busy = 0;
	}
}

function fade_in(){
	// alert(this.opacity);
	if (this.opacity < this.opacity_max){
		this.opacity = Math.min(this.opacity+this.opacity_step,this.opacity_max);
		this.set_layer_opacity();
		this.busy = 1;
		setTimeout(this.obj_name+'.fade_in();',this.opacity_timeout);
		// speed en dur = 100 pour compatibilitŽ IE.
	} else {
		this.opacity = this.opacity_max;
		this.set_layer_opacity();
		this.busy = 0;
	}
}

function set_layer_opacity(){
	if (browse_no_opacity) {
	} else if (browse_filter) {
	   	eval("document.getElementById('" + this.layer_name + "').style.filter = alpha(opacity=" + this.opacity + ");");
	} else {
		eval("document.getElementById('" + this.layer_name + "').style."+browse_opacity+" = " + this.opacity + ";");
   }
}