// JavaScript Document
/******************************************************************************************************
Copyright (c): Yves Dahan, 08/2003
e-mail: ygda.free.fr

Utilisation libre pour tout usage sous réserve du maintien de la présente mention de copyright.
*******************************************************************************************************/
function ScrollDiv(id){
	//alert(id);
	//alert(document.getElementById(id).style.width);
	if(this == window)
		return new ScrollDiv(id); //ScrollDiv() called as a Function
		var elt = document.getElementById(id);
		var w = elt.offsetWidth;
		var s = elt.parentNode.offsetWidth;
		if(!w || !s || s>w){
			this.scroll = Function(""); return;}
		var divStyle = elt.style;
		var offset = 0;
		var maxOffset = s-w;
		var timer = null;
		var self = this;
	 
		this.scroll =  function(dir,speed){
			var coef = 1, S = speed;
			while(S--)coef *= 2;
			if (timer)window.clearTimeout(timer);
			switch (dir){
				case 's': //stop
					break;
				case 'l': //left
					if(offset>maxOffset){
						offset -= coef;
						divStyle.left = Math.min(offset,0)+"px";
						timer = window.setTimeout(function(){self.scroll('l',speed)},25)}
					break;
				case 'r': //right
					if(0>offset){
						offset+=coef;
						divStyle.left = Math.max(offset,maxOffset)+"px";
						timer = window.setTimeout(function(){self.scroll('r',speed)},25)}
			}
		}
}

