function hide_div(p1,p2,p3) {
 if(DOM || MS) getElem(p1,p2,p3).style.visibility = "hidden";
 if(NS) getElem(p1,p2,p3).visibility = "hide";
}

function show_div(p1,p2,p3) {
 if(DOM || MS) getElem(p1,p2,p3).style.visibility = "visible";
 if(NS) getElem(p1,p2,p3).visibility = "show";
}

function is_visible_div(p1,p2,p3) {
	if (getElem(p1,p2,p3)) {
		if(DOM || MS) return (getElem(p1,p2,p3).style.visibility == "visible");
 		if(NS) return (getElem(p1,p2,p3).visibility == "show");
	}	
	return true; 
}

function is_show_div(p1,p2,p3) {
 var rep;
 if(DOM || MS) rep = getElem(p1,p2,p3).style.visibility;
 if(NS) rep = getElem(p1,p2,p3).visibility;
 return (rep == "show" || rep == "visible");	
}

function get_parent_div(p1,p2,p3) {
	return getElem(p1,p2,p3).offsetParent;
}

function get_parent_obj(obj) {
	return obj.offsetParent;
}

function get_x_div(p1,p2,p3) {
	return get_x_obj(getElem(p1,p2,p3));
}

function get_x_obj(obj) {
 	if (obj.tagName == "BODY") return parseInt(obj.offsetLeft);
  	else return get_x_obj(get_parent_obj(obj)) + parseInt(obj.offsetLeft);
} 

function get_y_div(p1,p2,p3) {
	return get_y_obj(getElem(p1,p2,p3));
}

function get_y_obj(obj) {
 	if (obj.tagName == "BODY") return parseInt(obj.offsetTop);
  	else return get_y_obj(get_parent_obj(obj)) + parseInt(obj.offsetTop);
} 

function get_x_relatif_div(p1,p2,p3) {
 if(!DOM && MS) return parseInt(getElem(p1,p2,p3).style.pixelLeft);
 else return parseInt(getElem(p1,p2,p3).style.left);
}

function get_y_relatif_div(p1,p2,p3) {
 if(!DOM && MS) return parseInt(getElem(p1,p2,p3).style.pixelTop);
 else return parseInt(getElem(p1,p2,p3).style.top);
}

function get_h_div(p1,p2,p3) {
 if(!DOM && MS) return parseInt(getElem(p1,p2,p3).offsetHeight);
 else return parseInt(getElem(p1,p2,p3).offsetHeight);
}

function get_l_div(p1,p2,p3) {
 if(!DOM && MS) return parseInt(getElem(p1,p2,p3).offsetWidth);
 else return parseInt(getElem(p1,p2,p3).offsetWidth);
}

function set_x_div(p1,p2,p3,x) {
 if(DOM || MS) getElem(p1,p2,p3).style.left = x;
 else { 
	if (OP) getElem(p1,p2,p3).style.pixelLeft = x;
	else if(NS) getElem(p1,p2,p3).left = x;
 }	 
}

function set_y_div(p1,p2,p3,y) {
 if(DOM || MS) getElem(p1,p2,p3).style.top = y;
 else { 
	if (OP) getElem(p1,p2,p3).style.pixelTop = y;
	else if(NS) getElem(p1,p2,p3).top = y;
 }	 
}

function set_h_div(p1,p2,p3,h) {
 if(DOM || MS) getElem(p1,p2,p3).style.height = h;
 else { 
	if (OP) getElem(p1,p2,p3).style.pixelHeight = h;
	else if(NS) getElem(p1,p2,p3).height = h;
 }	 
}

function set_l_div(p1,p2,p3,l) {
 if(DOM || MS) getElem(p1,p2,p3).style.width = l;
 else { 
	if (OP) getElem(p1,p2,p3).style.pixelWidth = l;
	else if(NS) getElem(p1,p2,p3).width = l;
 }	 
}

function set_xy_div(p1,p2,p3,x,y) {
 if(DOM || MS) {
     getElem(p1,p2,p3).style.left = x;
     getElem(p1,p2,p3).style.top = y;
 }
 else { 
   if (OP) {
	 	getElem(p1,p2,p3).style.pixelLeft = x;
		getElem(p1,p2,p3).style.pixelTop = y;
	 }	
	 else if(NS) {
	  getElem(p1,p2,p3).left = x;
	  getElem(p1,p2,p3).top = y;
 	 }
 }	 
}

function set_lh_div(p1,p2,p3,l,h) {
 if(DOM || MS) {
     getElem(p1,p2,p3).style.width = l;
     getElem(p1,p2,p3).style.height = h;
 }
 else { 
   if (OP) {
	 	getElem(p1,p2,p3).style.pixelWidth = l;
		getElem(p1,p2,p3).style.pixelHeight = h;
	 }	
	 else if(NS) {
	  getElem(p1,p2,p3).width = l;
	  getElem(p1,p2,p3).height = h;
 	 }
 }	 
}

function set_xylh_div(p1,p2,p3,x,y,l,h) {
 if(DOM || MS) {
     getElem(p1,p2,p3).style.left = x;
     getElem(p1,p2,p3).style.top = y;
     getElem(p1,p2,p3).style.width = l;
     getElem(p1,p2,p3).style.height = h;
 }
 else { 
   if (OP) {
	 	getElem(p1,p2,p3).style.pixelLeft = x;
		getElem(p1,p2,p3).style.pixelTop = y;
	 	getElem(p1,p2,p3).style.pixelWidth = l;
		getElem(p1,p2,p3).style.pixelHeight = h;
	 }	
	 else if(NS) {
	  getElem(p1,p2,p3).left = x;
	  getElem(p1,p2,p3).top = y;
	  getElem(p1,p2,p3).width = l;
	  getElem(p1,p2,p3).height = h;
 	 }
 }	 
}

function set_style_div(p1,p2,p3,style) {
	if (!OP) {
		if (style.is_style()) getElem(p1,p2,p3).style.cssText = style;
		else if (style.is_class()) set_class_div(p1,p2,p3,style);
	}
	else {
		if (style.is_style()) getElem(p1,p2,p3).setAttribute("style",style);
		else if (style.is_class()) set_class_div(p1,p2,p3,style);	
	}	 
}

function set_class_div(p1,p2,p3,classe) {
	if (classe.is_class()) getElem(p1,p2,p3).className = classe;
	else if (classe.is_style()) set_style_div(p1,p2,p3,classe);
}

function set_position_div(p1,p2,p3,position) {getElem(p1,p2,p3).style.position = position;}

function set_opacity_div(p1,p2,p3,opacity) {
	if (DOM && !MS && !OP) getElem(p1,p2,p3).style.MozOpacity = opacity;
	else if (MS) getElem(p1,p2,p3).style.filter = "alpha(opacity = "+opacity*100+")";
}

function set_clip_div(p1,p2,p3,l,r,t,b) {
 if(DOM || MS) 
   getElem(p1,p2,p3).style.clip = "rect(" + t + " " + r + " " + b + " " + l + ")";
 if(NS) 
  getElem(p1,p2,p3).clip = "rect(" + t + " " + r + " " + b + " " + l + ")";
}

function is_in_box(p1,p2,p3,x,y) {
	var x1 = get_x_div(p1,p2,p3);
	var y1 = get_y_div(p1,p2,p3);
	var h = get_h_div(p1,p2,p3);
	var l = get_l_div(p1,p2,p3);
	if (isNaN(l)) l = 10;
	if (isNaN(h)) h = 10;
	return (x > x1) && (x < x1+l) && (y > y1) && (y < y1+h);
}

function goto_div(p1,p2,p3,x,y,pas,speed,last_action) {
	move_div(p1,p2,p3,get_x_div(p1,p2,p3),get_y_div(p1,p2,p3),x,y,pas,speed,last_action);
}

function goto_x_div(p1,p2,p3,x,pas,speed,last_action) {
	move_x_div(p1,p2,p3,get_x_div(p1,p2,p3),x,pas,speed,last_action);
}

function goto_y_div(p1,p2,p3,y,pas,speed,last_action) {
	move_y_div(p1,p2,p3,get_y_div(p1,p2,p3),y,pas,speed,last_action);
}

function goto1_div(p1,p2,p3,x,y,div,speed,last_action) {
	move1_div(p1,p2,p3,get_x_div(p1,p2,p3),get_y_div(p1,p2,p3),x,y,div,speed,last_action);
}

function goto1_x_div(p1,p2,p3,x,div,speed,last_action) {
	move1_x_div(p1,p2,p3,get_x_div(p1,p2,p3),x,div,speed,last_action);
}

function goto1_y_div(p1,p2,p3,y,div,speed,last_action) {
	move1_y_div(p1,p2,p3,get_y_div(p1,p2,p3),y,div,speed,last_action);
}

function move1_div(p1,p2,p3,x1,y1,x2,y2,div,speed,last_action) {
	var ddx = x2 - x1;
	var ddy = y2 - y1;
	if (ddx != 0) {
		if (Math.abs(ddx) <= 0.5) x1 = x2;
		else {
			if (ddx > 0) x1 += Math.abs(ddx)/div;
			else x1 -= Math.abs(ddx)/div;
		}
	}	
	if (ddy != 0) {
		if (Math.abs(ddy) <= 0.5) y1 = y2;
		else {
			if (ddy > 0) y1 += Math.abs(ddy)/div;
			else y1 -= Math.abs(ddy)/div;
		}
	}
	if (ddx != 0 || ddy != 0) {
		set_xy_div(p1,p2,p3,x1,y1);
		setTimeout("move1_div('" + p1 + "','" + p2 + "','" + p3 + "'," + x1 + "," + y1 + "," + x2 + "," + y2 + "," + div + "," + speed  + ",'" + last_action + "');",speed);
	}
	else eval(last_action);		
}

function move1_x_div(p1,p2,p3,x1,x2,div,speed,last_action) {
	var ddx = x2 - x1;
	if (ddx != 0) {
		if (Math.abs(ddx) <= 0.5) x1 = x2;
		else {
			if (ddx > 0) x1 += Math.abs(ddx)/div;
			else x1 -= Math.abs(ddx)/div;
		}
	}	
	if (ddx != 0) {
		set_x_div(p1,p2,p3,x1);
		setTimeout("move1_x_div('" + p1 + "','" + p2 + "','" + p3 + "'," + x1 + "," + x2 + "," + div + "," + speed  + ",'" + last_action + "');",speed);
	}
	else eval(last_action);		
}

function move1_y_div(p1,p2,p3,y1,y2,div,speed,last_action) {
	var ddy = y2 - y1;
	if (ddy != 0) {
		if (Math.abs(ddy) <= 0.5) y1 = y2;
		else {
			if (ddy > 0) y1 += Math.abs(ddy)/div;
			else y1 -= Math.abs(ddy)/div;
		}
	}
	if (ddy != 0) {
		set_y_div(p1,p2,p3,y1);
		setTimeout("move1_y_div('" + p1 + "','" + p2 + "','" + p3 + "'," + y1 + "," + y2 + "," + div + "," + speed  + ",'" + last_action + "');",speed);
	}
	else eval(last_action);		
}

function move_div(p1,p2,p3,x1,y1,x2,y2,pas,speed,last_action) {
	var dx = (x2-x1)/pas;
	var dy = (y2-y1)/pas;
	set_xy_div(p1,p2,p3,x1,y1);
	move_div_rec(p1,p2,p3,x1,y1,x2,y2,dx,dy,speed,last_action);
}

function move_x_div(p1,p2,p3,x1,x2,pas,speed,last_action) {
	var dx = (x2-x1)/pas;
	set_x_div(p1,p2,p3,x1);
	move_x_div_rec(p1,p2,p3,x1,x2,dx,speed,last_action);
}

function move_y_div(p1,p2,p3,y1,y2,pas,speed,last_action) {
	var dy = (y2-y1)/pas;
	set_y_div(p1,p2,p3,y1);
	move_y_div_rec(p1,p2,p3,y1,y2,dy,speed,last_action);
}

function move_div_rec(p1,p2,p3,x,y,x2,y2,dx,dy,speed,last_action) {
	if (Math.abs(x2-x) < Math.abs(dx)) x = x2;
	else x += dx; 
	if (Math.abs(y2-y) < Math.abs(dy)) y = y2;
	else y += dy;
	
	set_xy_div(p1,p2,p3,x,y);

	if (x != x2 || y != y2) 
		setTimeout("move_div_rec('" + p1 + "','" + p2 + "'," + p3 + "," + x + "," + y + "," + x2 + "," + y2 + "," + dx + "," + dy + "," + speed + ",'" + last_action + "')",speed);
	else
		eval(last_action);	
}

function move_x_div_rec(p1,p2,p3,x,x2,dx,speed,last_action) {
	if (Math.abs(x2-x) < Math.abs(dx)) x = x2;
	else x += dx; 
	set_x_div(p1,p2,p3,x);
	if (x != x2) 
		setTimeout("move_x_div_rec('" + p1 + "','" + p2 + "'," + p3 + "," + x + "," + x2 + "," + dx + "," + speed + ",'" + last_action + "')",speed);
	else
		eval(last_action);	
}

function move_y_div_rec(p1,p2,p3,y,y2,dy,speed,last_action) {
	if (Math.abs(y2-y) < Math.abs(dy)) y = y2;
	else y += dy;
	set_y_div(p1,p2,p3,y);
	if (y != y2) 
		setTimeout("move_y_div_rec('" + p1 + "','" + p2 + "'," + p3 + "," + y + "," + y2 + "," + dy + "," + speed + ",'" + last_action + "')",speed);
	else
		eval(last_action);	
}

function move_clip_open_div(p1,p2,p3,x,y,dir,l,pas,speed,marge,last_action) {
	switch (dir)
	{
		case "left":
			set_clip_div(p1,p2,p3,'auto',(l-marge),'auto','auto');
			set_x_div(p1,p2,p3,x);
			break;
		case "right":
			set_clip_div(p1,p2,p3,(l-marge),'auto','auto','auto');
			set_x_div(p1,p2,p3,x);
			break;
		case "top":
			set_clip_div(p1,p2,p3,'auto','auto','auto',(l-marge));
			set_y_div(p1,p2,p3,y);
			break;
		case "bottom":
			set_clip_div(p1,p2,p3,'auto','auto',(l-marge),'auto');
			set_y_div(p1,p2,p3,y);
			break;
	}
	show_div(p1,p2,p3);
	move_clip_open_div_rec(p1,p2,p3,x,y,dir,l,pas,marge,speed,last_action);
}

function move_clip_open(p1,p2,p3,dir,pas,speed,marge,last_action) {
	var l = (dir == "right" || dir == "left")?get_l_div(p1,p2,p3):get_h_div(p1,p2,p3);
	var x = (dir == "right" || dir == "left")?((dir == "left")?l:0)+get_x_div(p1,p2,p3)-marge:get_x_div(p1,p2,p3);
	var y = (dir == "right" || dir == "left")?get_y_div(p1,p2,p3):((dir == "top")?l:0)+get_y_div(p1,p2,p3)-marge;
	move_clip_open_div(p1,p2,p3,x,y,dir,l,pas,speed,marge,last_action)
}

function move_clip_open_div_rec(p1,p2,p3,x,y,dir,l,pas,dl,speed,last_action) {
	if (Math.abs(l-(dl+(l/pas))) < (l/pas)) dl = l;
	else dl += l/pas;
	switch (dir)
	{
		case "left":
			set_x_div(p1,p2,p3,x-dl);
			set_clip_div(p1,p2,p3,'auto',dl,'auto','auto');
			break;
		case "right":
			set_x_div(p1,p2,p3,x-l+dl);
			set_clip_div(p1,p2,p3,l-dl,'auto','auto','auto');
			break;
		case "top":
			set_y_div(p1,p2,p3,y-dl);
			set_clip_div(p1,p2,p3,'auto','auto','auto',dl);
			break;
		case "bottom":
			set_y_div(p1,p2,p3,y-l+dl);
			set_clip_div(p1,p2,p3,'auto','auto',l-dl,'auto');			
			break;
	}

	if (dl != l) 
		setTimeout("move_clip_open_div_rec('" + p1 + "','" + p2 + "'," + p3 + "," + x + "," + y + ",'" + dir + "'," + l + "," + pas + "," + dl + "," + speed + ",'" + last_action + "')",speed);
	else
		eval(last_action);	
}

function move_clip_close_div(p1,p2,p3,x,y,dir,l,pas,speed,marge,last_action) {
	set_clip_div(p1,p2,p3,'auto','auto','auto','auto');
	switch (dir)
	{
		case "left":
			set_x_div(p1,p2,p3,x);
			break;
		case "right":
			set_x_div(p1,p2,p3,x);
			break;
		case "top":
			set_y_div(p1,p2,p3,y);
			break;
		case "bottom":
			set_y_div(p1,p2,p3,y);
			break;
	}
	move_clip_close_div_rec(p1,p2,p3,x,y,dir,l,pas,0,speed,marge,last_action);
}

function move_clip_close(p1,p2,p3,dir,pas,speed,marge,last_action) {
	var l = (dir == "right" || dir == "left")?get_l_div(p1,p2,p3):get_h_div(p1,p2,p3);
	var x = get_x_div(p1,p2,p3);
	var y = get_y_div(p1,p2,p3);
	move_clip_close_div(p1,p2,p3,x,y,dir,l,pas,speed,marge,last_action)
}

function move_clip_close_div_rec(p1,p2,p3,x,y,dir,l,pas,dl,speed,marge,last_action) {
	var lm = l - marge;
	if (Math.abs(lm-(dl+(lm/pas))) < (lm/pas)) dl = lm;
	else dl += lm/pas;
	switch (dir)
	{
		case "left":
			set_x_div(p1,p2,p3,x-dl);
			set_clip_div(p1,p2,p3,dl,'auto','auto','auto');
			break;
		case "right":
			//set_x_div(p1,p2,p3,x-l+dl);
			set_clip_div(p1,p2,p3,dl,'auto','auto','auto');
			break;
		case "top":
			set_y_div(p1,p2,p3,y-dl);
			set_clip_div(p1,p2,p3,'auto','auto',dl,'auto');
			break;
		case "bottom":
			//set_y_div(p1,p2,p3,y-l+dl);
			set_clip_div(p1,p2,p3,'auto','auto',dl,'auto');			
			break;
	}

	if (dl != lm) 
		setTimeout("move_clip_close_div_rec('" + p1 + "','" + p2 + "'," + p3 + "," + x + "," + y + ",'" + dir + "'," + l + "," + pas + "," + dl + "," + speed + "," + marge + ",'" +  last_action + "')",speed);
	else {
		hide_div(p1,p2,p3);
		eval(last_action);	
	}	
}

function opacity_open_div(p1,p2,p3,dl,speed,last_action) {
	opacity_open_div_rec(p1,p2,p3,0.05,dl,speed,last_action);
}

function opacity_open_div_rec(p1,p2,p3,opacity,dl,speed,last_action) {
	set_opacity_div(p1,p2,p3,opacity);
	opacity += dl;

	if (opacity < 1) 
		setTimeout("opacity_open_div_rec('" + p1 + "','" + p2 + "'," + p3 + "," + opacity + "," + dl + "," + speed + ",'" + last_action + "')",speed);
	else 
		eval(last_action);
}

function opacity_close_div(p1,p2,p3,dl,speed,last_action) {
	opacity_close_div_rec(p1,p2,p3,0.95,dl,speed,last_action);
}

function opacity_close_div_rec(p1,p2,p3,opacity,dl,speed,last_action) {
	set_opacity_div(p1,p2,p3,opacity);
	opacity -= dl;

	if (opacity > 0) 
		setTimeout("opacity_close_div_rec('" + p1 + "','" + p2 + "'," + p3 + "," + opacity + "," + dl + "," + speed + ",'" + last_action + "')",speed);
	else {
		//hide_div(p1,p2,p3);
		eval(last_action);
	}		
}

function opacity_loop_div(p1,p2,p3,nbr_loop,dl,speed) {
	opacity_loop_div_rec(p1,p2,p3,true,nbr_loop,dl,speed);
}

function opacity_loop_div_rec(p1,p2,p3,sens,nbr_loop,dl,speed) {
	var last_action = "";
	if (nbr_loop != 0) last_action = "opacity_loop_div_rec(\""+p1+"\",\""+p2+"\","+p3+","+(!sens)+","+((!sens)?nbr_loop-1:nbr_loop)+","+dl+","+speed+");";
	if (sens) opacity_open_div(p1,p2,p3,dl,speed,last_action);
	else opacity_close_div(p1,p2,p3,dl,speed,last_action);
}

function cligne_div(p1,p2,p3,loop,speed,etat) {
	if (etat) hide_div(p1,p2,p3);
	else show_div(p1,p2,p3);
	if (loop > 0) setTimeout("cligne_div('" + p1 + "','" + p2 + "','" + p3 + "'," + (loop - 1) + "," + speed + "," + !etat + ");",speed);
	else {
		if (loop < 0) setTimeout("cligne_div('" + p1 + "','" + p2 + "','" + p3 + "'," + loop + "," + speed + "," + !etat + ");",speed);
		else show_div(p1,p2,p3);
	}	
}

function intersec(id1,id2) {
	var x1 = get_x_div("id",id1,null);
	var x2 = get_x_div("id",id2,null);
	var y1 = get_y_div("id",id1,null);
	var y2 = get_y_div("id",id2,null);
	var l1 = get_l_div("id",id1,null);
	var l2 = get_l_div("id",id2,null);
	var h1 = get_h_div("id",id1,null);
	var h2 = get_h_div("id",id2,null);
	var dx,dy;
	if (x1 < x2) dx = x1 + l1 - x2;
	else dx = x2 + l2 - x1;
	if (y1 < y2) dy = y1 + h1 - y2;
	else dy = y2 + h2 - y1;
	return (dx >= 0 && dy >= 0);
}

function loop_img(p1,p2,p3,speed,indice) {
	var i = 5;
	var elem;
	var imgliste = "";
	
	if (arguments.length > 5) {
		while(arguments[i])  
			imgliste += ((imgliste=="")?"'":",'") + arguments[i++] + "'";
		i = indice + 1;
		if (i+5 >= arguments.length) i = 0;
		elem = getElem(p1,p2,p3);
		if (elem) {
			if (elem.tagName == "IMG") {
				elem.src = arguments[indice+5];
				setTimeout("loop_img('" + p1 + "','" + p2 + "','" + p3 + "'," + speed + "," + i + "," + imgliste + ");",speed);
			}
		}
	}
	else alert("manque les photos");
	return true;
}
