

// ==============================================================
// HANDLES SCROLLER/S
// Modified from Aaron Boodman http://webapp.youngpup.net/?request=/components/ypSimpleScroll.xml
// mixed ypSimpleScroll with dom-drag script and allowed multiple scrolelrs through array instances
// (c)2004 Sergi Meseguer (http://zigotica.com/), 04/2004:
// ==============================================================
var theHandle = []; var theRoot = []; var theThumb = []; var FondThumb = []; var theScroll = []; var thumbTravel = []; var ratio = [];

function instantiateScroller(count, id, left, top, width, height, speed){
	if(document.getElementById) {
		theScroll[count] = new ypSimpleScroll(id, left, top, width, height, speed);
	}
}

function reloadDragger(count, handler, root, thumb, minX, maxX, minY, maxY) {
	var divRoot=document.getElementById(root);
	
	for(var i=0; i<divRoot.childNodes.length; i++) {
		if((divRoot.childNodes[i].id=="up"+count) || (divRoot.childNodes[i].id=="dn"+count) || (divRoot.childNodes[i].id==thumb) || (divRoot.childNodes[i].id=="fond_"+thumb)) {
			divRoot.removeChild(divRoot.childNodes[i]);
			i=i-1;
		}
	}
	/* Lien de retour en haut de page
	if(document.getElementById("divretour_"+count)) {
		document.getElementById("divretour_"+count).parentNode.removeChild(document.getElementById("divretour_"+count));
	}
	*/
	createDragger(count, handler, root, thumb, minX, maxX, minY, maxY);
}

function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY){
	
	var d, lyrId1, lyrId2;
	d = document;
	lyrId1 = theScroll[count].id + "Container"
	lyrId2 = theScroll[count].id + "Content"
	var container = theScroll[count].y.dom ? d.getElementById(lyrId1) : theScroll[count].y.ie ? d.all[lyrId1] : d.layers[lyrId1]
	var content = theScroll[count].y.ns4 ? theScroll[count].container.layers[lyrId2] : theScroll[count].y.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	var docH = Math.max(theScroll[count].y.ns4 ? content.document.height : content.offsetHeight, theScroll[count].clipH)
	var scrollH = docH - theScroll[count].clipH
	
	if(scrollH>0) {

		var buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="'+serveur_site+'/img/design/up.gif" width="11" height="11"></a></div><div class="dn"  id="dn'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="'+serveur_site+'/img/design/dn.gif" width="11" height="11"></a></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="'+serveur_site+'/img/design/thumb.gif" width="11" height="11"></div><div class="fond_thumb" id="fond_'+thumb+'" style="left: 135px; top: 15px;"></div>';
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;
		
		// Insertion du lien de retour en haut de page
		//addToTopLink(count);

		theRoot[count]   = document.getElementById(root);
		theThumb[count]  = document.getElementById(thumb);
		FondThumb[count]  = document.getElementById('fond_'+thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		theThumb[count].style.left = parseInt(minX+15) + "px";
		FondThumb[count].style.left = parseInt(minX+16) + "px";
		thisup.style.left = parseInt(minX+15) + "px";
		thisdn.style.left = parseInt(minX+15) + "px";
		theThumb[count].style.border =0;
		theThumb[count].style.top = parseInt(minY) + "px";
		FondThumb[count].style.top = parseInt(minY-1) + "px";
		thisup.style.top = 0 + "px";
		thisdn.style.top = parseInt(minY+maxY) + "px";
		//thisdn.style.top = 15 + "px";

		theScroll[count].load();

		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		Drag.init(theThumb[count], null, minX+15, maxX+15, minY, maxY);
		
		// the number of pixels the thumb can travel vertically (max - min)
		thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY;
		FondThumb[count].style.height = parseInt(thumbTravel[count]+13) + "px";

		// the ratio between scroller movement and thumbMovement
		ratio[count] = theScroll[count].scrollH / thumbTravel[count];

		theThumb[count].onDrag = function(x, y) {
			theScroll[count].jumpTo(null, Math.round((y - theThumb[count].minY) * ratio[count]));
		}
		
	}
}
	
/*
// AddToTopLink
// Ajoute le lien de retour en haut de page.
function addToTopLink(count) {
	var Div=document.getElementById('scroll'+count+'Content');
	
	var divretour=document.createElement('div');
		divretour.setAttribute('id', 'divretour_'+count);
		
	var hr=document.createElement('hr');
		hr.setAttribute('class', 'separateur');
		hr.setAttribute('className', 'separateur');
	
	var p=document.createElement('p');
		p.setAttribute('class', 'right');
		p.setAttribute('className', 'right');
		
	var TopLink=document.createElement('a');
		TopLink.setAttribute('href', '#');
		TopLink.onclick=function() {
				theScroll[count].overrideScrollSpeed(200000);
				theScroll[count].startScroll('90', count);
				return false;
			}
		TopLink.setAttribute('title', trad_retour_hautdepage);
		TopLink.innerHTML='&#187; '+trad_retour_hautdepage;
		
		p.appendChild(TopLink);
		
	divretour.appendChild(hr);
	divretour.appendChild(p);
	
	Div.appendChild(divretour);
}
*/

// Initialisation
addLoadHandler(function(){
		if(theScroll.length>0) {
		for(var i=0;i<theScroll.length;i++){
			createDragger(i, "handle"+i, "root"+i, "thumb"+i, -12, -12, 15, theScroll[i].clipH-20);
		}
	}
}) 