//FONCTION recherche d'objet (v1.0)
	function findObj(theObj, theDoc){
		
		var p, i, foundObj;
	  
		if(!theDoc) theDoc = document;
		if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
			theDoc = parent.frames[theObj.substring(p+1)].document;
			theObj = theObj.substring(0,p);
		}
		if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
		for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj];
		for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document);
		if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
		 
		return foundObj;
	}
	
//FONCTION recherche un noeud fils ayant l'id voulu (v 1.0)
function getChildById(parent_node, child_node_id){
	var iterative = (arguments[2]||false), i=0, child_node;
	
	while((parent_node.children&&(child_node = parent_node.children[i++]))||(child_node = parent_node.childNodes[i++])){
		if((child_node.id && child_node.id==child_node_id)||(child_node.getAttribute&&child_node.getAttribute('id')==child_node_id)){return child_node;}
	}
	if(iterative){
		i=0;
		while((parent_node.children&&(child_node = parent_node.children[i++]))||(child_node = parent_node.childNodes[i++])){
			if(child_node.hasChildNodes()&&(child_node=getChildById(child_node, child_node_id, true))){
				return child_node;
			}
		}
	}
	return false;
}


//FONCTION supprime l'élément (v 1.0)
function element_supprimer(str_nom){
	var target_element;
	
	if(target_element = findObj(str_nom)){
		target_element.parentNode.removeChild(target_element);
	}
}


// FONCTION retourne la position de l'objet (DOM) (v1.0)
function get_position(this_obj){
	var obj_left = obj_top = 0;
	if (this_obj.offsetParent){
		obj_left = this_obj.offsetLeft;
		obj_top = this_obj.offsetTop;
		while (this_obj = this_obj.offsetParent){
			obj_left += this_obj.offsetLeft;
			obj_top += this_obj.offsetTop;
		}
	}
	return [obj_left, obj_top];
}

// FONCTION retourne la position de l'objet (DOM) (v1.0)
function get_size(this_obj){
	var obj_width = obj_height = 0;
	if (this_obj.offsetParent){
		obj_width = this_obj.offsetWidth;
		obj_height = this_obj.offsetHeight;
	}
	return [obj_width, obj_height];
}


//FONCTION positionne un objet (v1.5)
function position_set(this_obj, int_top, int_left){	
	if(this_obj){
		this_obj.style.left = int_top+"px";
		this_obj.style.top = int_left+"px";
	}
}


//FONCTION centre un objet (v2.0) [requiert : getWindowSize]
function position_center(this_obj){
	if(this_obj ){
		var parent_dims = (this_obj.offsetParent!=document.body)?[this_obj.offsetParent.offsetWidth,this_obj.offsetParent.offsetHeight]:getWindowSize();
		this_obj.style.left = ((parent_dims[0]-this_obj.offsetWidth)/2)+"px";
		this_obj.style.top  = ((parent_dims[1]-this_obj.offsetHeight)/2)+"px";
	}
}


//FONCTION supperpose deux objets (v1.0) [requiert : get_position]
function position_same(this_obj, source_obj){	
	if(this_obj && source_obj){
		var arr_pos = get_position(source_obj);
		this_obj.style.left = arr_pos[0];
		this_obj.style.top = arr_pos[1];
	}
}


//FONCTION place un objet au niveau du pointeur (v1.0) [requiert : mouse_position_detect]
function position_pointeur(this_obj){
	if(!document.mouse_position)mouse_position_detect();
	if(this_obj){
		this_obj.style.left = document.mouse_position[0];
		this_obj.style.top = document.mouse_position[1];
	}
}


//FONCTION démarre le déplacement d'un objet [usage : this_obj.onmousedown=startDrag; || mouse_position_detect(); /.../ startDrag(this_obj);]
function startDrag(){
	if(!(arguments[0]&&arguments[0].style)){
		this_obj=(window.event)?window.event.srcElement:arguments[0].target;
	}else this_obj=arguments[0];
	if(!document.dragPile||document.dragPile.length==0)document.dragPile=new Array();
	if(!document.mouse_position){mouse_position_detect(); mouse_position((window.event)?window.event:arguments[0]);}
	for(var i in document.dragPile){
		if(document.dragPile[i]==this_obj)return false;
	}
	document.dragPile.push(this_obj);
	document.dragMouseSP=[document.mouse_position[0], document.mouse_position[1]];
	document.onmousemove=function(e){
		mouse_position(e);						
		for(var i in document.dragPile){
			document.dragPile[i].style.left = (document.dragPile[i].style.left.replace('px', '')*1 + document.mouse_position[0]-document.dragMouseSP[0]) +"px";
			document.dragPile[i].style.top = (document.dragPile[i].style.top.replace('px', '')*1 + document.mouse_position[1]-document.dragMouseSP[1]) +"px";	
		}
		document.dragMouseSP=[document.mouse_position[0], document.mouse_position[1]];
	};
}


//FONCTION arrête le déplacement d'un objet [usage : this_obj.onmouseup=stopDrag; || stopDrag(this_obj);]
function stopDrag(){
	if(!(arguments[0]&&arguments[0].style)){
		this_obj = (window.event)?window.event.srcElement:arguments[0].target;
	}else this_obj = arguments[0];
	if(!document.dragPile||document.dragPile.length==0)return true;
	for(var i in document.dragPile){
		if(document.dragPile[i]==this_obj){
			document.dragPile.splice(i,1);
		}
	}
	return false;
}


//FONCTION detection de la position de la souris (v 1.5)
function mouse_position_detect(){
	mouse_position = function(e){
		var posx = 0;
		var posy = 0;
		if(!e && window.event) var e = window.event;
		if(e.pageX||e.pageY){
			posx = e.pageX;
			posy = e.pageY;
		}else if(e.clientX||e.clientY){
			posx = e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
			posy = e.clientY+document.body.scrollTop+document.documentElement.scrollTop;
		}
		document.mouse_position = [posx, posy];
	}		
	if (document.captureEvents) document.captureEvents(Event.MOUSEMOVE);	
	document.onmousemove=mouse_position;
}


//FONCTION vérifie si onmouseout correspond à une vraie sortie (v 1.0)
function is_true_mouseout(e, obj){
	if (!e) var e = window.event;	
	if(obj) var tg = obj;
	else var tg = (window.event) ? e.srcElement : e.target;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY'){
		reltg= reltg.parentNode;
		if (reltg== tg) return false;
	}
	return true;
}


//FONCTION precharge les images (v1.0)
function img_preload(){
	//preload_img(str_url_img_1 [, str_url_img_2 [, ...]])
	
	if(document.images){//vérifie le support
		//crée le tableau des images préchargé s'il n'existe pas
		if(!document.arr_img_preload)document.arr_img_preload=new Array();
		
		var j = document.arr_img_preload.length;
		
		for(var i=0; i<arguments.length; i++){
			document.arr_img_preload[j+i] = new Image();
			document.arr_img_preload[j+i].src = arguments[i];
		}
	}
}


//FONCTION paramètrage de la transparence d'un objet (v 1.2)
function setAlpha(this_obj, int_alpha){
	this_obj.style.opacity = int_alpha;								//firefox
	this_obj.style.filter = (int_alpha >= 1)?'':'alpha(opacity='+(int_alpha*100)+')';	//ie
	this_obj.style.MozOpacity = int_alpha;							//netscape
}


//FONCTION effet de fondu sur un objet (v 1.0)
function Fade(){
	//Fade(this_obj, int_alpha_in, int_alpha_out, int_ms_duration, int_distribution, str_eval_at_end);
	var int_ms_periode_maj = 1000/50;	// période de rafraichissement en ms (50 Hz => 1000/50 = 20 ms)
	
	if(arguments.length >= 4){
		//Ajout d'un fondu sur un objet
		//récupération des paramètres
		var this_obj		= arguments[0];
		var int_alpha_in	= arguments[1];
		var int_alpha_out	= arguments[2];
		var int_ms_duration = arguments[3];
		var int_distribution= Math.min(Math.max(arguments[4]?arguments[4]:0,-100),100);
		var str_eval_at_end = arguments[5]?arguments[5]:"";
		
		//transforme le paramètre int_distribution [-100, +100] centré sur 0, pour obtenir le coef [1/10, 10] centré sur 1
		var fl_coef_distribution = 1+9/100*((int_distribution>0)?int_distribution:int_distribution/10);
			
		//applique l'alpha de début à l'objet			
		setAlpha(this_obj, int_alpha_in);
		
		//Enregistre les paramètres
		if(!document.arr_fxfade_pile) document.arr_fxfade_pile=new Array();
		document.arr_fxfade_pile.push([this_obj, int_alpha_in, int_alpha_out, 0, int_ms_duration, fl_coef_distribution, str_eval_at_end]);
		
		//Démarre l'appel récursif
		if(!document.int_fxfade_intervalID) document.int_fxfade_intervalID=setInterval("Fade();", int_ms_periode_maj);

		document.infos_fxfade="";

	}else{
		//Appel récursif pour l'éxecution du fondu
		for(var i in document.arr_fxfade_pile){
					
			//mise à jour du temps écoulé
			document.arr_fxfade_pile[i][3] += int_ms_periode_maj;
			
			//récupération des paramètres
			var int_alpha_in = document.arr_fxfade_pile[i][1], int_alpha_out = document.arr_fxfade_pile[i][2], int_ms_temp_ecoule = document.arr_fxfade_pile[i][3], int_ms_temp_total = document.arr_fxfade_pile[i][4], fl_coef_distribution = document.arr_fxfade_pile[i][5], coef, alpha;
			
			//calcul de l'alpha
			alpha = Math.pow(int_ms_temp_ecoule/int_ms_temp_total, fl_coef_distribution)*(int_alpha_out-int_alpha_in)+int_alpha_in;
			document.infos_fxfade += "["+i+"] t = "+int_ms_temp_ecoule+" alpha = "+alpha+"\n";
			//vérification du temps écoulé, application de l'alpha
			if(int_ms_temp_ecoule >= int_ms_temp_total-int_ms_periode_maj/2){
				setAlpha(document.arr_fxfade_pile[i][0], int_alpha_out);
				eval(document.arr_fxfade_pile[i][6]);
				delete(document.arr_fxfade_pile[i]);
			}else{
				setAlpha(document.arr_fxfade_pile[i][0], alpha);
			}
		}
		
		if(!document.arr_fxfade_pile.length){
			//arrêt de l'appel récursif si la pile de fondu est vide
			clearInterval(document.int_fxfade_intervalID);
			document.int_fxfade_intervalID = false;
		}
	}		
}


//FONCTION déplacement progressif (v 1.0)
function move(this_obj, left_dest, top_dest, ms_duration){
	//move(this_obj, left_destination, top_destination, ms_duration, fade_in_out_distribution);
			//avec -100 < fade_in_out_distribution < 100
	var pos_start=new Array(), time=new Date(), start_time, fade_in=arguments[4]||0, this_obj_index=false, coef;
	time=time.getTime();
	
	//initialisation
	if(arguments[8]){		//mode callback
		this_obj_index=this_obj;
		this_obj=document.move_fx_this_obj_arr[this_obj_index];
		pos_start[0]=arguments[6];
		pos_start[1]=arguments[7];
		start_time=arguments[5];
	}else{					//mode appel initial
		//gestion de la pile d'appel
		if((!document.move_fx_this_obj_arr)||(document.move_fx_this_obj_arr[0]==0)){
			document.move_fx_this_obj_arr=new Array();
			document.move_fx_this_obj_arr[0]=0;
			this_obj_index=1;
		}else if(document.move_fx_this_obj_arr[0]>25){
			for(var i=1; i<=25; i++){
				if(!document.move_fx_this_obj_arr[i]){
					this_obj_index=i;
					break;
				}
			}
		}
		if(!this_obj_index)this_obj_index=document.move_fx_this_obj_arr.length;
		//initialisation des variables
		document.move_fx_this_obj_arr[this_obj_index]=this_obj;
		document.move_fx_this_obj_arr[0]++;
		pos_start=get_position(this_obj);
		start_time=time;
	}
	
	//arret de la boucle si déplacement terminé
	if((time-start_time)>=ms_duration){
		position_set(this_obj, left_dest, top_dest);
		delete(document.move_fx_this_obj_arr[this_obj_index]);
		document.move_fx_this_obj_arr[0]--;
		return;
	}
	
	//MAJ position
	coef=Math.pow((time-start_time)/ms_duration, 1+9/100*((fade_in>0)?fade_in:fade_in/10));
	position_set(this_obj, coef*(left_dest-pos_start[0])+pos_start[0], coef*(top_dest-pos_start[1])+pos_start[1]);
	
	//appel callback
	setTimeout("move("+this_obj_index+", "+left_dest+", "+top_dest+", "+ms_duration+","+fade_in+","+start_time+","+pos_start[0]+","+pos_start[1]+", 1)",20);
}


//FONCTION Interdiction du clic droit (v 1.0)
function disableRightClick(e){
	//usage, n'importe où dans le script : disableRightClick();
	
	//var message = "reproduction interdite";
	//mode initialisation
	if(!document.rightClickDisabled){
		if(document.layers){
			document.captureEvents(Event.MOUSEDOWN);
			document.onmousedown = disableRightClick;
		}else document.oncontextmenu = disableRightClick;
		return document.rightClickDisabled = true;
	}
	//mode blocage sur click droit
	if(document.layers || (document.getElementById && !document.all)){
		if (e.which==2||e.which==3){
			//alert(message);
			return false;
		}
	}else{
		//alert(message);
		return false;
	}
}

function getWindowSize(){
	if(window.innerWidth) return [window.innerWidth, window.innerHeight]
	else if(document.documentElement&&(document.documentElement.clientWidth)) return [document.documentElement.clientWidth, document.documentElement.clientHeight];
	else if(document.body&&(document.body.clientWidth||document.body.clientHeight)) return [document.body.clientWidth,document.body.clientHeight];
	return [0,0];
}

function getScrollPosition(){
	return [
		((window.pageXOffset instanceof Number)&&window.pageXOffset)||document.body.scrollLeft|| (document.documentElement && document.documentElement.scrollLeft),
		((window.pageYOffset instanceof Number)&&window.pageYOffset)||document.body.scrollTop|| (document.documentElement && document.documentElement.scrollTop)
	]
}