var timeoutdrag;
var startmove=false;
var hauteurscroll=440;
var tailledoc;
var offset=0;
var selection=true;

function init(){
	loaddrag();
	load=1;   //action des effet onmousemove
}

function startdrag(offset){
	startmove=true;
    selection=false;
	movecursor();
}

function noSelect(){
	return false;
}

function backSelect(){
	return true;
}

function movecursor(){
	
	/* Permet de ne pas selectionner du texte en même temps que l'on utilise le scroll */
	get("contenttoscroll").focus();
	document.onselectstart = noSelect; 
	
	ylocal=y-get("content").offsetTop-offset;
	clearTimeout(timeoutdrag);

	positiondoc=get("contenttoscroll").offsetTop;
	offsetdrag = get("drag").offsetTop;
	positionmax=tailledoc-hauteurscroll;
	
	if(startmove&&load){
		coord=ylocal-10;
		if(coord<0) coord=0;
		if(coord>hauteurscroll)coord=hauteurscroll;
		{	
			get("drag").style.top=coord+"px";
			get("contenttoscroll").style.top=(-(coord*(positionmax))/hauteurscroll)+"px";
			
		}
		timeoutdrag=setTimeout("movecursor()",10);
	}
	return true;
}

function stopdrag(){
	startmove=false;
	selection=true;
	clearTimeout(timeoutdrag);
	document.onselectstart = backSelect;
}
	
function loaddrag(){
	try{
		tailledoc=get("contenttoscroll").offsetHeight-20;
		//alert('tailledoc:'+tailledoc+' - hauteurscroll:'+hauteurscroll);
		
		if(tailledoc<hauteurscroll+20){
			get("drag").style.visibility="hidden";
			get("scrollbg").style.visibility="hidden";
			get("decalage").style.visibility="hidden";
			get("contenttoscroll").style.width="470px";
		}
		else
		{
			get("contenttoscroll").style.padding="0px 15px 0px 0px";
			tailledoc=get("contenttoscroll").offsetHeight;
			get("decalage").style.visibility="visible";
			get("drag").style.visibility="visible";
			get("scrollbg").style.visibility="visible";
		}
	}
	catch(e){
		alert('Erreur dans le catch');
	}
}
	

