


var theHandle = []; var theRoot = []; var theThumb = []; 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 createDragger(count, handler, root, thumb, minX, maxX, minY, maxY){

		var buttons = '<div class="up" id="up'+count+'">';
		buttons +='		<a href="#" onMouseDown="theScroll['+count+'].scrollNorth(\''+count+'\')" onMouseUp="theScroll['+count+'].endScroll()" onclick="return false;"><img src="'+root_path+'images/up.gif" ></a>';
		buttons +='</div>';
		buttons +='<div class="dn"  id="dn'+count+'"">';
		buttons +='		<a href="#" onMouseDown="theScroll['+count+'].scrollSouth(\''+count+'\')" onMouseUp="theScroll['+count+'].endScroll()" onclick="return false;"><img src="'+root_path+'images/dn.gif"></a>';
		buttons +='</div>';
		buttons +='<div class="thumb" id="'+thumb+'" style="right: 140px; top: 15px; ">';
		buttons +='		<img src="'+root_path+'images/thumb.gif" width="15" height="'+theScroll[count].handlerH+'" id="mainHandler'+count+'">';
		buttons +='</div>';
		
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;

		theRoot[count]   = document.getElementById(root);
		theThumb[count]  = document.getElementById(thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		var thisHandler = document.getElementById("mainHandler"+count);
		theThumb[count].style.right = parseInt(minX+6) + "px";
		thisup.style.right = parseInt(minX+2) + "px";
		thisdn.style.right = parseInt(minX+2) + "px";
		
		theThumb[count].style.border =0;
		theThumb[count].style.top = parseInt(minY) + "px";
		
		thisup.style.top = 0 + "px";
		thisdn.style.top = parseInt(minY+maxY) + "px";
		
		//thisdn.style.top = 15 + "px";
		
		
		
		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		Drag.init(theThumb[count], null, minX+6, maxX+6, minY+2, maxY-theScroll[count].handlerH+17,true);
		
		// the number of pixels the thumb can travel vertically (max - min)
		thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY 

		// 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]));
		}
}	

// INITIALIZER:
// ==============================================================
// ala Simon Willison http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(fn) {
		var old = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = fn;
		}
		else {
			window.onload = function() {
				old();
				fn();
			}
		}
	}
addLoadEvent(
	function(){
		if(theScroll.length>0) {
			for(var i=0;i<theScroll.length;i++){
				
				theScroll[i].load();
				//alert("afterload "+(theScroll[i].clipH+" : "+theScroll[i].handlerH+30));
				if (theScroll[i].clipH>(theScroll[i].handlerH+30))
				createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 15, theScroll[i].clipH-30);
			}
		}
	}
) 