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, root, thumb, minX, maxX, minY, maxY, color, offset, bar){
		var buttons = '<div class="thumb" id="'+thumb+'"><img src="/img/scroller.gif" width="10" height="20"></div>';
		if(document.getElementById('scroll'+count+'Content').scrollHeight>maxY)
		{
			document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;

			theRoot[count]   = document.getElementById(root);
			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{
			if(bar)
			{
				document.getElementById('scroll'+count+'Bar').style.display='block';
			}
		}
}	

function addLoadEvent(fn) {
	window.onload = function() {
		Shadowbox.init();
		fn();
		document.getElementById('pre_loading').style.display = 'none';
        document.getElementById('pre_loading').id = 'pre_loaded';
        loadTimeout = null;
	}
}
addLoadEvent(function(){
		if(theScroll.length>0) {
		for(var i=0;i<theScroll.length;i++){
			createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 0, theScroll[i].clipH, theColor[i], theOffset[i], theBar[i]);
		}
	}
}) 