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);
		//createDragger(count, "handle"+count, "bsc_lm_root"+count, "thumb"+count, theScroll[count].clipW, theScroll[count].clipW, 4, theScroll[count].clipH-15);
	}
}
 
function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY){

					 
 		var hContainer = document.getElementById("bsc_lm_root" + count + "Container"); 
		var hContent = document.getElementById("bsc_lm_root" + count + "Content"); 
		//alert(count + "=" + hContainer.offsetHeight + "=" + hContent.offsetHeight);
		var visible = hContainer.offsetHeight < hContent.offsetHeight;

		theRoot[count]   = document.getElementById(root);
		theThumb[count]  = document.getElementById(thumb);

		var thisScr = document.getElementById("scr" + count);

		thisScr.style.left = parseInt(minX) + 2 + "px";
		thisScr.style.display = (visible ? "block" : "none");
		thisScr.style.height = parseInt(maxY) + "px";
		thisScr.style.width = "1px";
		
		theThumb[count].style.left = parseInt(minX) + "px";		
		theThumb[count].style.border =0;
		theThumb[count].style.top = parseInt(minY) + "px";
		theThumb[count].style.display = (visible ? "block" : "none");
		theThumb[count].style.width = "6px";

		theScroll[count].load();
 	
		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		Drag.init(theThumb[count], null, minX, maxX, minY, maxY);
		
		// 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();
         }
      }
   }*/
   
function addLoadEvent()
{
	if(theScroll.length>0) {
		for(var i=0;i<theScroll.length;i++){
			theScroll[i].load();
			createDragger(i, "handle"+i, "bsc_lm_root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 4, theScroll[i].clipH-15);
		}
	}
} 

