var timeoutdrag;
var startmove=false;
var tailledoc;
var selection=true;
var offset;

function init1(){
	load=1;   
}

var x;
var y; 
var load = 0; 

function position(e) { 
	if(load)
	{	x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
		x=x-get("alldiv").offsetLeft;
		y =(navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
		y=y-get("alldiv").offsetTop;
	}
}

if (navigator.appName.substring(0,3) == "Net") document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = position;

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// SCROLL avec barre -------------------------------------------------------------------------------------------------------------------------------------------------------

var myTimeout;
var gomove = false;
var hauteurcontenu = -1; 
var hauteurconteneur = -1;
var hauteurscroll = -1;
var hauteurscrollbg = -1;
var ybase; var laststop;
var firstclick = 1;
var selection=true;
var diff = 287;

function myscroll(loc_contenu,loc_divid,loc_scrollerid,loc_conteneur){
	if (firstclick == 0){
		get(loc_divid).focus();
		document.onselectstart = noSelect; 
		var maxpx = hauteurscrollbg - 3;
		clearTimeout(myTimeout);
		var tempo = ((y-ybase)/diff);
		if (((y-ybase)/diff)	> 1){ tempo = 1; }
		if (((y-ybase)/diff)	< 0){ tempo = 0; }
		if (hauteurconteneur - hauteurcontenu > 0){
			tempo = tempo * (-(hauteurconteneur - hauteurcontenu)); 
		}
		if (hauteurconteneur - hauteurcontenu < 0){
			tempo = tempo * (hauteurconteneur - hauteurcontenu); 
		}
		if ((y - ybase) > 2 && (y-ybase)< diff){
			get(loc_scrollerid).style.top = y - ybase + 'px';
			get(loc_divid).style.top = tempo + 'px';
		} 
		myTimeout = setTimeout(function(){myscroll(loc_contenu,loc_divid,loc_scrollerid,loc_conteneur);},1);
	}
	else{
		firstclick = 0;
		ybase = y;
		myTimeout = setTimeout(function(){myscroll(loc_contenu,loc_divid,loc_scrollerid,loc_conteneur);},1);
	}
}
function loadmyscroll(conteneurid,contenuid,scrollbgid,scrollid){
	try {
		hauteurcontenu = get(contenuid).offsetHeight; 
		hauteurconteneur = get(conteneurid).offsetHeight;
		hauteurscrollbg = get(scrollbgid).offsetHeight;
		hauteurscroll = get(scrollid).offsetHeight;//alert(hauteurcontenu+' dans '+hauteurconteneur);
		if (hauteurcontenu > hauteurconteneur){
			get(scrollbgid).style.visibility = 'visible';
			get(scrollid).style.visibility = 'visible';
		}
	}
	catch(e){}
}
function arretemyscroll(){
	selection=true;
	document.onselectstart = backSelect;
	clearTimeout(myTimeout);
}
function noSelect(){
	return false;
}
function backSelect(){
	return true;
}

// -----------------------------------------------------------------------------------------------------------------------

var mytime;
var deplacement = false;
var totalheight = -1; 
var boxheight = -1;

function move(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps){
	var letop = get(loc_divtoscroll).style.top;
	var lalongueur = letop.length - 2;
	var topactuel = parseFloat(letop.substring(0,lalongueur));
	clearTimeout(mytime);
	var decale;
	
	if (loc_type == 'bas'){
		decale = loc_total - loc_boxheight + topactuel;
		if (decale > loc_pas){
			decale = loc_pas;
		}
		if (decale > 0){
			get(loc_divtoscroll).style.top = topactuel - decale + 'px';
			get(loc_up).style.visibility = 'visible';
			if ((topactuel-decale) == (loc_boxheight - loc_total)){
				get(loc_down).style.visibility = 'hidden';
			}
			mytime = setTimeout(function(){move(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps);},loc_temps);
		}
	}
	if (loc_type == 'haut'){
		decale = (-(topactuel));
		if (decale > loc_pas){
			decale = loc_pas;
		}
		if (decale > 0){
			get(loc_divtoscroll).style.top = topactuel + decale + 'px';
			get(loc_down).style.visibility = 'visible';
			if ((topactuel+decale) == 0){
				get(loc_up).style.visibility = 'hidden';
			}
			mytime = setTimeout(function(){move(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps);},loc_temps);
		}
	}
}
function startminiscroll(conteneur,contenu,bottomid,scrollbgid){
	try {
		totalheight = get(contenu).offsetHeight;
		boxheight = get(conteneur).offsetHeight;//alert('Total = '+totalheight+' px\nBox = '+boxheight);
		if (totalheight > boxheight){
			get(bottomid).style.visibility = 'visible';
			get(scrollbgid).style.visibility = 'visible';
		}
	}
	catch(e){}
}
function stopminiscroll(){
	deplacement=false;
	clearTimeout(mytime);
}


// -----------------------------------------------------------------------------------------------------------------------

var mytime2;
var deplacement2 = false;
var totalheight2 = -1; 
var boxheight2 = -1;

function move2(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps){
	var letop = get(loc_divtoscroll).style.top;
	var lalongueur = letop.length - 2;
	var topactuel = parseFloat(letop.substring(0,lalongueur));
	clearTimeout(mytime2);
	var decale;
	
	if (loc_type == 'bas'){
		decale = loc_total - loc_boxheight + topactuel;
		if (decale > loc_pas){
			decale = loc_pas;
		}
		if (decale > 0){
			get(loc_divtoscroll).style.top = topactuel - decale + 'px';
			get(loc_up).style.visibility = 'visible';
			if ((topactuel-decale) == (loc_boxheight - loc_total)){
				get(loc_down).style.visibility = 'hidden';
			}
			mytime2 = setTimeout(function(){move(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps);},loc_temps);
		}
	}
	if (loc_type == 'haut'){
		decale = (-(topactuel));
		if (decale > loc_pas){
			decale = loc_pas;
		}
		if (decale > 0){
			get(loc_divtoscroll).style.top = topactuel + decale + 'px';
			get(loc_down).style.visibility = 'visible';
			if ((topactuel+decale) == 0){
				get(loc_up).style.visibility = 'hidden';
			}
			mytime2 = setTimeout(function(){move(loc_type,loc_total,loc_divtoscroll,loc_boxheight,loc_up,loc_down,loc_pas,loc_temps);},loc_temps);
		}
	}
}

function startminiscroll2(conteneur,contenu,bottomid,scrollbgid){
	try {
		totalheight2 = get(contenu).offsetHeight;
		boxheight2 = get(conteneur).offsetHeight;//alert('Total = '+totalheight+' px\nBox = '+boxheight);
		if (totalheight2 > boxheight2){
			get(bottomid).style.visibility = 'visible';
			get(scrollbgid).style.visibility = 'visible';
		}
	}
	catch(e){}
}
function stopminiscroll2(){
	deplacement2=false;
	clearTimeout(mytime2);
}