


//>SCROLLBAR

function c_barscroll (_idbar,_idcur,_sens,_pas,_flh,_flb) {
	//property
	this.Obar = getOb(_idbar)
	this.Ocur = getOb(_idcur)
	this.flh = getOb(_flh)
	this.flb = getOb(_flb)
	this.htmax=getHt(this.Obar)
	this.sens = _sens	// 0=> vertical / 1=> Horizontal
	this.pas = _pas

	this.min = 0
	this.max = (this.sens)? (getLg(this.Obar)-getLg(this.Ocur)) : (getHt(this.Obar)-getHt(this.Ocur))
	this.pos =0
	this.accel = 1
	this.encours = false
	this.ind=0
	this.nbtour=50
	this.fctmaj = ""		// Lance cette fonction à chaque itération d'anim
	this.fctfin = ""		// Lance cette fonction à chaque fin d'anim

	//method
	this.move = move
	this.incr = incr
	this.decr = decr
	this.start = start
	this.stop = stop

	this.poscour = poscour		// retourne la position courante en %
	this.place = place		// place le curseur à la position donnée en %
	// Cache / Montre le scroll
	this.cache = cache
	this.montre = montre

	return this
	
}

function move() { if (this.sens) enx(this.Ocur,this.pos); else eny(this.Ocur,this.pos); if(this.fctmaj!="") eval(this.fctmaj) }

function start() { this.encours=true }
function stop() { this.encours=false; window.focus() }

function cache() { hide(this.Obar); hide(this.Ocur);display_hide(this.flh);display_hide(this.flb);}
function montre() {show(this.Obar);display_show(this.flh);anim(this.Obar.id,this.htmax,this.ind,this.nbtour); show(this.Ocur);show_flb(this.flb.id);}

function incr() { this.pos+=parseInt(this.pas*this.accel); if (this.pos>this.max) this.pos=this.max; this.move() }
function decr() { this.pos-=parseInt(this.pas*this.accel); if (this.pos<this.min) this.pos=this.min; this.move() }

function poscour() { return 100-Math.abs((this.pos-this.min)*100/(this.max-this.min)) }
function place(pc) {this.pos = parseInt(this.min+(this.max-this.min)*pc/100); this.move() }

animation=null
animation_encours=0;
function anim(_Obscroll,_htmax,_ind,_nbtour) {
animation_encours=1;
var Obscroll = eval(getOb(_Obscroll))
var Obscroll_htmax= eval(_htmax)
var Obscroll_ind= eval(_ind)
var Obscroll_nbtour= eval(_nbtour)

posy = prop(0,Obscroll_htmax,35,Obscroll_ind,Obscroll_nbtour)
	clp(Obscroll,0,20,posy,0)
	Obscroll_ind=Obscroll_ind+1
	if((Obscroll_ind<Obscroll_nbtour) && (posy<Obscroll_htmax))
	{
	animation=setTimeout("anim('"+_Obscroll+"',"+Obscroll_htmax+","+Obscroll_ind+","+Obscroll_nbtour+")",100)	
	}
	else {
	clearTimeout(animation)
		clp(Obscroll,0,20,Obscroll_htmax,0);
		show(Obscroll);
		animation_encours=0;
	}
}
timer_flb=null
function show_flb(id_flb)
{
if (animation_encours==1)
{timer_flb=setTimeout("show_flb('"+id_flb+"')",20)
}
else
{
clearTimeout(timer_flb)
display_show(getOb(id_flb))
}
}

//<SCROLLBAR




//>SCROLLTXT barre de scroll
function c_txtscroll(_Oout,_Oin,_sens,_pas,_bloc) { // construit l'élement de texte dynamique
	//property
	// objet physique à bouger OUT / IN
	this.Oout = getOb(_Oout)
	
	this.Oin = getOb(_Oin)
	this.sens = _sens	// 0=> vertical / 1=> Horizontal
	this.pas = _pas		// Pas d'avancement du scroll
	this.min = (this.sens)? (getLg(this.Oout)-getLg(this.Oin)) : (getHt(this.Oout)-getHt(this.Oin))// Borne inférieure du scroll
	this.max =0	// Borne supérieure du scroll
	this.pos = 0		// Position courante du scroll
	this.whellon=0
	this.accel = 3
	this.bloc = _bloc			// Défilement par bloc => taille du bloc

	this.encours = false			// En cours de scroll => plus d'évènements supplémentaires

	this.fctmaj = ""		// Lance cette fonction à chaque itération d'anim
	this.fctfin = ""		// Lance cette fonction à chaque fin d'anim

	//method
	this.depasse = depasse	// Indique si scroll nécéssaire
	this.bouge = bouge
	this.ancre = ancre
	this.deplace = deplace
	this.activatewhell=activatewhell
	this.debut = debut	// vrai si c le début
	this.fin = fin		// vrai si c la fin

	this.poscourtxt = poscourtxt	// pos courante en %	

	this.placetxt = placetxt	// place txt à la pos donnée en %

	this.startxt = startxt		// anim en cours
	this.stoptxt = stoptxt		// pas d'anim en cours

	return this
}
function depasse() { return(this.min<0) }
function activatewhell(){this.whellon=1}
function debut() { return(this.pos==this.min) }
function fin() { return(this.pos==this.max) }

function startxt() { this.encours=true }
function stoptxt() { this.encours=false; window.focus() }

function deplace() {
	if(this.sens) enx(this.Oin,this.pos)
	else eny(this.Oin,this.pos)
	/*en principe pas bessoin*/
	clp(this.Oin,-gety(this.Oin),getLg(this.Oout)-getx(this.Oin),getHt(this.Oout)-gety(this.Oin),-getx(this.Oin))
	/*/en principe pas bessoin*/
	if(this.fctmaj!="") eval(this.fctmaj)
}


function bouge(nbpix,sens) {
	this.pos+=(sens*2-1)*nbpix
	if (sens) { if(this.pos>this.max) this.pos=this.max }
	else { if(this.pos<this.min) this.pos=this.min }
	this.deplace()
}

function poscourtxt() { return 100-Math.abs((this.pos-this.min)*100/(this.max-this.min));}

function placetxt(pc) {this.pos = parseInt(this.min+(this.max-this.min)*pc/100); this.deplace() }

// FONCTION NON METHODE => SETTIMEOUT

function animbloc(_Obtxt,_sens,_lm) {
	// Deplace jusqu'à nbpix pixel
	var Obtxt = eval(_Obtxt)

	if(!animbloc.arguments[3]&&animbloc.arguments[3]!=0) {
		animbloc.arguments[4] = Obtxt.bloc
		animbloc.arguments[3] = Obtxt.pos -(1-2*_sens)*Obtxt.bloc
	}

	var npx=animbloc.arguments[4]

	if (npx>0) {

		Obtxt.encours=true
		npx-=parseInt(npx/Obtxt.pas)+1
		Obtxt.pos = animbloc.arguments[3] + (1-2*_sens)*npx

		if(_lm)	{
			if(!_sens) Obtxt.pos=(Obtxt.pos<Obtxt.min)?Obtxt.min:Obtxt.pos
			else Obtxt.pos=(Obtxt.pos>Obtxt.max)?Obtxt.max:Obtxt.pos
		}
		Obtxt.deplace()

		setTimeout("animbloc('"+_Obtxt+"',"+_sens+","+_lm+","+animbloc.arguments[3]+","+npx+")",20)	
	}
	else { Obtxt.encours=false; if(this.fctfin!="") eval(this.fctfin) }
}

function scroller_txt(_Obtxt,_sens) {
	window.focus() 
	var Obtxt = eval(_Obtxt)
	if (!Obtxt.encours) {  Obtxt.startxt(); scrolling(_Obtxt,_sens,'') }
}

function scrolling(_Obtxt,_sens,_fct) {
	var Obtxt = eval(_Obtxt)
	Obtxt.bouge(Obtxt.pas*Obtxt.accel,_sens)
	if(Obtxt.debut()) { if(_fct!="") eval(_fct) }
	else if(Obtxt.encours) setTimeout("scrolling('"+_Obtxt+"',"+_sens+",'"+_fct+"')",20)
}

//<SCROLLTXT


//>SCROLLBARTXT
function c_bartxtscroll(_nom,_Obar,_Otxt) { // scroll bar+txt

	//property
	this.Onom = _nom		// nom de l'Ob Scrollbar
	this.Obar = eval(_Obar)
	this.Otxt = eval(_Otxt)

	this.etatbar = 0
	this.etattxt = 1

	//method
	this.majObar = majObar
	this.majOtxt = majOtxt

	this.fctmajObar = fctmajObar
	this.fctmajOtxt = fctmajOtxt
	this.isfctbar = fctmajObar
	this.isfcttxt = fctmajOtxt

	
	return this
}

function majObar() {this.Obar.place(this.Otxt.poscourtxt()) }
function majOtxt() { this.Otxt.placetxt(this.Obar.poscour())}


function fctmajObar(etat) { this.etatbar=etat; this.Obar.fctmaj=""; if(etat) this.Obar.fctmaj=this.Onom+".majOtxt()"}

function fctmajOtxt(etat) {this.etattxt=etat; this.Otxt.fctmaj=""; if(etat) this.Otxt.fctmaj=this.Onom+".majObar()"}

function isfctbar() { return this.etatbar }

function isfcttxt() { return this.etattxt }

//<SCROLLBARTXT


//>SOURIS

var dfo_Obsouris //objet souris en cours d'action

function c_souris(_dfofct,_dfoargfct) { // construit l'élement de suivit de souris

	//property
	this.dfofct = _dfofct
	this.dfoargfct = _dfoargfct
	this.sourisX = -1
	this.sourisY = -1

	//method
	this.evt_on = evt_on	// Lancement des évènements

	return this
}

function evt_on() {
	if (window.captureEvents) window.captureEvents( Event.MOUSEMOVE, Event.MOUSEUP )
	document.onmousemove=capture
	document.onmouseup=evt_off
	dfo_Obsouris=this
}

function evt_off() {
	document.onmousemove=null
	document.onmouseup=null
	dfo_Obsouris.sourisX=-1
	dfo_Obsouris.sourisY=-1
	dfo_Obsouris=null
}

function capture(e) {
	if (document.all) e=event

	if (dfo_Obsouris.sourisX!=-1||dfo_Obsouris.sourisY!=-1) {
	
		var decalageX = e.clientX - dfo_Obsouris.sourisX+document.body.scrollLeft;

		var decalageY = e.clientY - dfo_Obsouris.sourisY+document.body.scrollTop;


		eval(dfo_Obsouris.dfofct+"("+decalageX+","+decalageY+","+dfo_Obsouris.dfoargfct+")")

	}
	dfo_Obsouris.sourisX = e.clientX+document.body.scrollLeft;
	dfo_Obsouris.sourisY = e.clientY+document.body.scrollTop;

}

//<SOURIS

// fonction appelée par la capture du mousemove
function maj_scroll(decalX,decalY) {

	dfobar=eval(maj_scroll.arguments[2])
	dfotxt=eval(maj_scroll.arguments[3])

	var decal=(dfobar.sens)? decalX : decalY

	var fctb= dfobar.fctmaj, fctt = dfotxt.fctmaj
	dfobar.fctmaj=""
	dfotxt.fctmaj=""

	dfobar.pos += ((dfobar.pos + decal)>=dfobar.min&&((dfobar.pos + decal)<=dfobar.max))?decal:0
	dfotxt.placetxt(dfobar.poscour())
	dfobar.move()

	dfobar.fctmaj=fctb
	dfotxt.fctmaj=fctt

}


function wheelmouse(id_ob) {
lobjet= eval(id_ob);
	if(lobjet.whellon) 
	{
		n=event.wheelDelta
		lobjet.accel=8;
		scroller_txt(id_ob,(n>0));
		lobjet.stoptxt();
		lobjet.accel=1;
	}
}


/*ancre dans le scrollen Dhtml*/
/*lien s'ecrit<a href="#_" onclick="ancre(divcontenan,iddelancre)">Le système immunitaire digestif</A>
ancre toute bete <a id="ancre1"></a>*/
function ancre(contenant,iddiv){
deplacement=((getOffsetPosition(iddiv, 'Top'))-(getOffsetPosition(contenant, 'Top')));
scroll1.bouge(deplacement,0)
}

/*savoir la position*/

getOffsetPosition = function(inID, inTYPE)
{
 var iVal = 0;
 var oObj = document.getElementById(inID);
 var sType = 'oObj.offset' + inTYPE;
 while (oObj && oObj.tagName != 'BODY') {
  iVal += eval(sType);
  oObj = oObj.offsetParent;
 }
 return iVal;
}


