function TScroll(idDiv,evnt) {
//constructeur
	this.Constructor = TConstructorScroll;
//Attribut
	this.Id = this.Constructor(idDiv,evnt);
	this.Minutor = null;
	this.Direction = "rigth";
	this.Speed = 1;
	this.SpeedX = 1;
	this.SpeedY = 1;
	this.Limite = 7;
	this.Pause = 3000;
	this.Distance = 100;
	this.Sens = true;
//M&eacute;thodes		
	this.Start = TStartScroll;
	this.Run = TRunScroll;
	this.RunDiapo = TRunDiapo;
	this.StopDiapo = TStopDiapo;
	this.Stop = TStopScroll;
	this.SetDirection = TSetDirection;
	this.GetDirection = TGetDirection;
	this.SetSpeed = TSetSpeed;
	this.AddSpeed = TAddSpeed;
	this.SupSpeed = TSupSpeed;
}

function TConstructorScroll(idDiv,evnt) {
	getElem("id",idDiv,null).style.overflow = "hidden";
	setCont("id",idDiv,null,"<div id=\"scroll_" + idDiv + "\" style=\"position:relative;left:0;top:0\">" + getCont("id",idDiv,null) + "</div>");
	if (evnt) {
		add_event("id",idDiv,null,"mousemove","change_direction");
		add_event("id",idDiv,null,"click","stop_defil");
	}	
	return idDiv
}

function TStartScroll() {
	var h = get_h_div("id","scroll_"+this.Id,null);
	var l = get_l_div("id","scroll_"+this.Id,null);
	var hfen = get_h_div("id",this.Id,null);
	var lfen = get_l_div("id",this.Id,null);
	
	switch (this.Direction) {
		case "top":
			set_xy_div("id","scroll_"+this.Id,null,0,0);break;
		case "bottom":
			set_xy_div("id","scroll_"+this.Id,null,0,hfen-h);break;
		case "left":
			set_xy_div("id","scroll_"+this.Id,null,0,0);break;
		case "rigth":
			set_xy_div("id","scroll_"+this.Id,null,lfen-l,0);break;
	}		
}

function TRunScroll() {
	if (!this.Minutor) 
		this.Minutor = setInterval("defil(\""+this.Id+"\")",120);
}

function TRunDiapo() {
	if (!this.Minutor) 
		this.Minutor = setTimeout("defil_diapo(\""+this.Id+"\")",30);
}

function TStopDiapo() {
	if (this.Minutor) clearTimeout(this.Minutor);
	this.Minutor = null;
}

function TStopScroll() {
	if (this.Minutor) clearInterval(this.Minutor);
	this.Minutor = null;
}

function TSetDirection(direction) {
	this.Direction = direction;
}

function TGetDirection() {
	var direction = "";
	if (!this.Sens) {
		switch (this.Direction) {
			case "top": direction="bottom";break;
			case "bottom": direction="top";break;
			case "left": direction="rigth";break;
			case "rigth": direction="left";break;
			case "topleft": direction="bottomrigth";break;
			case "bottomleft": direction="toprigth";break;
			case "toprigth": direction="bottomleft";break;
			case "bottomrigth": direction="topleft";break;
		}
	}
	else direction = this.Direction;	
	return direction;		
}

function TAddSpeed(speed) {
	this.Speed+=(speed==undefined)?1:speed;
}

function TSetSpeed(speed) {
	this.Speed=(speed==undefined)?1:speed;
}

function TSupSpeed(speed) {
	this.Speed-=(speed==undefined)?1:speed;
}

function defil(idDiv)
{
	var scroll = eval(idDiv);
	var x = get_x_relatif_div("id","scroll_"+idDiv);
	var y = get_y_relatif_div("id","scroll_"+idDiv);
	var h = get_h_div("id","scroll_"+idDiv);
	var l = get_l_div("id","scroll_"+idDiv);
	var hfen = get_h_div("id",idDiv);
	var lfen = get_l_div("id",idDiv);
	var SpeedX = scroll.SpeedX; 
	var SpeedY = scroll.SpeedY;
	var speed =  scroll.Speed;
	var direction = scroll.GetDirection();

	switch (direction) {
		case "top":
			if (y < -h) y = hfen + (2*speed); 
			set_y_div("id","scroll_"+idDiv,null,(y-speed));break;
		case "bottom":
			if (y > hfen) y = -(h + (2*speed));
			set_y_div("id","scroll_"+idDiv,null,(y+speed));break;
		case "left":
			if (x < -l) x = lfen + (2*speed);
			set_x_div("id","scroll_"+idDiv,null,(x-speed));break;
		case "rigth":
			if (x > lfen) x = -(l + (2*speed));
			set_x_div("id","scroll_"+idDiv,null,(x+speed));break;
		case "topleft":
			if (y < -h) y = hfen + (2*SpeedY); 
			set_y_div("id","scroll_"+idDiv,null,(y-SpeedY));
			if (x < -l) x = lfen + (2*SpeedX);
			set_x_div("id","scroll_"+idDiv,null,(x-SpeedX));break;
		case "bottomleft":
			if (y > hfen) y = -(h + (2*SpeedY));
			set_y_div("id","scroll_"+idDiv,null,(y+SpeedY));
			if (x < -l) x = lfen + (2*SpeedX);
			set_x_div("id","scroll_"+idDiv,null,(x-SpeedX));break;
		case "toprigth":
			if (y < -h) y = hfen + (2*SpeedY); 
			set_y_div("id","scroll_"+idDiv,null,(y-SpeedY));
			if (x > lfen) x = -(l + (2*SpeedX));
			set_x_div("id","scroll_"+idDiv,null,(x+SpeedX));break;
		case "bottomrigth":
			if (y > hfen) y = -(h + (2*SpeedY));
			set_y_div("id","scroll_"+idDiv,null,(y+SpeedY));
			if (x > lfen) x = -(l + (2*SpeedX));
			set_x_div("id","scroll_"+idDiv,null,(x+SpeedX));break;
	}		
}

function defil_diapo(idDiv,dist)
{
	var avance = (dist == undefined)?0:dist; 
	var scroll = eval(idDiv);
	var x = get_x_relatif_div("id","scroll_"+idDiv);
	var y = get_y_relatif_div("id","scroll_"+idDiv);
	var h = get_h_div("id","scroll_"+idDiv);
	var l = get_l_div("id","scroll_"+idDiv);
	var hfen = get_h_div("id",idDiv);
	var lfen = get_l_div("id",idDiv);
	var speed =  scroll.Speed;
	var direction = scroll.Direction;
	avance += speed;
	if (avance <= scroll.Distance) {	
		switch (direction) {
			case "top":
				if (y < -h) y = hfen-1; 
				set_y_div("id","scroll_"+idDiv,null,(y-speed));break;
			case "bottom":
				if (y > hfen) y = -h+1;
				set_y_div("id","scroll_"+idDiv,null,(y+speed));break;
			case "left":
				if (x < -l) x = lfen-1;
				set_x_div("id","scroll_"+idDiv,null,(x-speed));break;
			case "rigth":
				if (x > lfen) x = -l+1;
				set_x_div("id","scroll_"+idDiv,null,(x+speed));break;
		}
	}
	else {
		switch (direction) {
			case "top"://alert((y/scroll.Distance)+" : "+Math.floor(y/scroll.Distance));
				set_y_div("id","scroll_"+idDiv,null,(scroll.Distance+1)*Math.round(y/scroll.Distance));break;
			case "bottom"://alert((scroll.Distance+1)*Math.ceil(y/scroll.Distance));
				set_y_div("id","scroll_"+idDiv,null,(scroll.Distance+1)*Math.ceil(y/scroll.Distance));break;
			case "left":
				if (x < -l) x = lfen-1;
				set_x_div("id","scroll_"+idDiv,null,(scroll.Distance+1)*Math.round(x/scroll.Distance));break;
			case "rigth":
				if (x > lfen) x = -l+1;
				set_x_div("id","scroll_"+idDiv,null,(scroll.Distance+1)*Math.ceil(x/scroll.Distance));break;
		}
	}		
	
	if (avance > scroll.Distance) 	
		this.Minutor = setTimeout("defil_diapo(\""+idDiv+"\")",scroll.Pause);
	else	
		this.Minutor = setTimeout("defil_diapo(\""+idDiv+"\","+avance+")",30);	
}

function change_direction(e) {
	var scroll = eval(this.id);
	var xmouse = get_mouse_x_abs(e);
	var ymouse = get_mouse_y_abs(e);
	var h = get_h_div("id",this.id);
	var l = get_l_div("id",this.id);
	var x = get_x_div("id",this.id);
	var y = get_y_div("id",this.id);
	var deltax = (xmouse-x-(l/2));
	var deltay = (ymouse-y-(h/2));
	var xdiv = l/(l-2*Math.abs(deltax)+0.01);
	var ydiv = h/(h-2*Math.abs(deltay)+0.01);
	scroll.Direction = ((deltay>=0)?"bottom":"top")+((deltax>=0)?"rigth":"left");
	scroll.SpeedX = Math.floor(Math.abs(xdiv-1));
	if (scroll.SpeedX > scroll.Limite) scroll.SpeedX = scroll.Limite;
	scroll.SpeedY = Math.floor(Math.abs(ydiv-1));
	if (scroll.SpeedY > scroll.Limite) scroll.SpeedY = scroll.Limite;
}

function stop_defil(e) {
	var scroll = eval(this.id);
	if (scroll.Minutor) scroll.Stop();
	else scroll.Run();
}
