
var theHandle = []; var therootb = []; var thethumbb = []; var theScroll = []; var thumbbTravel = []; 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, rootb, thumbb, minX, maxX, minY, maxY){

		var buttons = '<div class="upb" id="upb'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="krok-images/up.gif" width="26" height="20"></a></div><div class="dnb"  id="dnb'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="krok-images/dn.gif" width="26" height="20"></a></div><div class="thumbb" id="'+thumbb+'" style="left: 134px; top: 15px;"><a href="#"><img src="krok-images/spacer.gif" width="19" height="19"></a></div>';
		document.getElementById(rootb).innerHTML = buttons + document.getElementById(rootb).innerHTML;

		therootb[count]   = document.getElementById(rootb);
		thethumbb[count]  = document.getElementById(thumbb);
		var thisupb = document.getElementById("upb"+count);
		var thisdnb = document.getElementById("dnb"+count);
		thethumbb[count].style.left = parseInt(minX+15) + "px";
		thisupb.style.left = parseInt(minX+15) + "px";
		thisdnb.style.left = parseInt(minX+15) + "px";
		thethumbb[count].style.border =0;
		thethumbb[count].style.top = parseInt(minY) + "px";
		thisupb.style.top = 0 + "px";
		thisdnb.style.top = parseInt(minY+maxY) + "px";
		//thisdnb.style.top = 15 + "px";

		theScroll[count].load();

		//Drag.init(theHandle[count], therootb[count]); //not draggable on screen
		Drag.init(thethumbb[count], null, minX+15, maxX+15, minY, maxY);
		
		// the number of pixels the thumbb can travel vertically (max - min)
		thumbbTravel[count] = thethumbb[count].maxY - thethumbb[count].minY;

		// the ratio between scroller movement and thumbbMovement
		ratio[count] = theScroll[count].scrollH / thumbbTravel[count];

		thethumbb[count].onDrag = function(x, y) {
			theScroll[count].jumpTo(null, Math.round((y - thethumbb[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++){
			createDragger(i, "handle"+i, "rootb"+i, "thumbb"+i, theScroll[i].clipW, theScroll[i].clipW, 15, theScroll[i].clipH-30);
		}
	}
}) 