// GESTION DU SCROLLING DU CALQUE DE TEXTE
//If you want it to move faster you can set this lower, it's the timeout:
var speed = 30, MinSpeed = 30, MaxSpeed = 0;

//Sets variables to keep track of what's happening
var loop, timer

//Object constructor
function makeObj(obj,nest){
	function moveIt(x,y){
		this.x = x
		this.y = y
		this.css.left = this.x+px
		this.css.top = this.y+px
	}

	nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bsw.dom?document.getElementById(obj):bsw.ie4?document.all[obj]:bsw.ns4?eval(nest+'document.'+obj):0;
	this.css=bsw.dom?document.getElementById(obj).style:bsw.ie4?document.all[obj].style:bsw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bsw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bsw.ns4?this.css.clip.height:this.el.offsetHeight
	this.moveIt=moveIt; this.x=0; this.y=0;
	this.obj = obj + "Object"
	eval(this.obj + "=this")
	return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bsw.ns4||window.opera?"":"px";

function scrollable_div (fct_scroll, divText, divScroll) {
	this.oFctScroll = fct_scroll;
	this.oCont = new makeObj(divScroll);
	this.oScrollContenu = new makeObj(divText,divScroll);
	this.oScrollContenu.moveIt(0,0);
	
	this.oCont.css.visibility = "visible";
	
	this.goDown = function (move) {
		if (this.oScrollContenu.y > this.oCont.clipHeight - this.oScrollContenu.scrollHeight) {
			this.oScrollContenu.moveIt(0,this.oScrollContenu.y-move)
			if (loop) setTimeout(this.oFctScroll+"(true,"+move+")",speed)
		}
	}
	
	this.goUp = function (move) {
		if (this.oScrollContenu.y < 0) {
			this.oScrollContenu.moveIt(0,this.oScrollContenu.y-move)
			if (loop) setTimeout(this.oFctScroll+"(false,"+move+")",speed)
		}
	}
	
	return this;
}

function scrollContenu (isDown, move) {
	if (isDown)
		scrollable_contenu.goDown(move);
	else
		scrollable_contenu.goUp(move);
}

function scrollMenuD (isDown, move) {
	if (isDown)
		scrollable_menuD.goDown(move);
	else
		scrollable_menuD.goUp(move);
}

function scrollMenuG (isDown, move) {
	if (isDown)
		scrollable_menuG.goDown(move);
	else
		scrollable_menuG.goUp(move);
}


var scrolltextLoaded = false
//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) {
			scrollable_contenu.goDown(speed);
			scrollable_menuD.goDown(speed);
			scrollable_menuG.goDown(speed);
		}
		else {
			scrollable_contenu.goUp(speed);
			scrollable_menuD.goUp(speed);
			scrollable_menuG.goUp(speed);
		}
	}
}

//Stops the scrolling (called on mouseout)
function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}

function handle(delta) {
	if (delta < 0)
		scroll(15);
	else
		scroll(-15);
	
	noScroll();
}
/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;


