var theHandle = []; var theRoot = []; var theThumb = []; var theScroll = []; var thumbTravel = []; var ratio = []; theColor = []; theOffset = []; theBar = [];

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

function createDragger(count, handler, thumb, minX, maxX, minY, maxY, color, offset, bar){
		var buttons = '<div class="thumb" id="'+thumb+'"><img src="/img/scroller/scroller_' + color + '.gif" width="10" height="20"></div>';
        
        theRoot[count] = document.getElementById('root' + count);
        
        theRoot[count].style.width = theScroll[count].clipW + "px";
        theRoot[count].style.height = theScroll[count].clipH + "px";
        
		if(document.getElementById('scroll'+count+'Content').scrollHeight>maxY)
		{
			theRoot[count].innerHTML = buttons + theRoot[count].innerHTML;
            
            theBar[count] = document.getElementById('scroll' + count + 'Bar');
            theBar[count].style.left = parseInt(minX) + "px";
            theBar[count].style.top = parseInt(minY - offset) + "px";
            theBar[count].style.height = theScroll[count].clipH + offset * 2 + "px";

			theThumb[count] = document.getElementById(thumb);
			theThumb[count].style.left = parseInt(minX) + "px";
			theThumb[count].style.border =0;
			theThumb[count].style.top = parseInt(minY-offset) + "px";
	
			theScroll[count].load();
	
			Drag.init(theThumb[count], null, minX, maxX, minY-offset, maxY-20+offset);
			
			thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY;
	
			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]));

			}
			document.getElementById('scroll'+count+'Bar').style.display='block';
		}else{
            document.getElementById('scroll'+count+'Bar').style.display='none';
		}
}	

function addLoadEvent(fn) {
      var old = window.onload;
      if (typeof window.onload != 'function') {
         window.onload = function() {
         fn();
         Shadowbox.init();
         }
      }
      else {
         window.onload = function() {
         fn();
         Shadowbox.init();
         }
      }
   }
addLoadEvent(function(){
		if(theScroll.length>0) {
		for(var i=0;i<theScroll.length;i++){
			createDragger(i, "handle"+i, "thumb"+i, theScroll[i].clipW + 4, theScroll[i].clipW + 4, 0, theScroll[i].clipH, theColor[i], theOffset[i], theBar[i]);
		}
	}
}) 