

// ==============================================================
// HANDLES SCROLLER/S
// Modified from Aaron Boodman http://webapp.youngpup.net/?request=/components/ypSimpleScroll.xml
// mixed ypSimpleScroll with dom-drag script and allowed multiple scrolelrs through array instances
// (c)2004 Sergi Meseguer (http://zigotica.com/), 04/2004:
// ==============================================================
var theHandle = []; var theRoot = []; var theThumb = []; var theScroll = []; var thumbTravel = []; var ratio = [];

function instantiateScroller(count, id, left, top, width, height, speed, buttons_top, buttons_bottom, no_thumb){
	if (buttons_top=="undefined" || buttons_top==null) {
		var buttons_top = 0;
	}
	if (buttons_bottom=="undefined" || buttons_bottom==null) {
		var buttons_bottom = 0;
	}
	if (no_thumb=="undefined" || no_thumb==null) {
		var no_thumb = 0;
	}
	  
	if(document.getElementById) {		
		theScroll[count] = new ypSimpleScroll(count, id, left, top, width, height, speed, buttons_top, buttons_bottom,no_thumb); 
	}
}

function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY, buttons_top, buttons_bottom, no_thumb){
		var upH = 15;
		var dnH = 15;
		var thumbH = 15;
		
		var buttons = '<div id="'+theScroll[count].id+'ButtonsContainer"><div class="thumbbg" id="thumbbg'+count+'">&nbsp;</div><div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth('+count+')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;" onmousedown="theScroll['+count+'].overrideScrollSpeed(200)" onmouseup="theScroll['+count+'].overrideScrollSpeed(70)"><img src="../_images/scroll_arrow_top.gif"></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth('+count+')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;" onmousedown="theScroll['+count+'].overrideScrollSpeed(200)" onmouseup="theScroll['+count+'].overrideScrollSpeed(70)"><img src="../_images/scroll_arrow_bottom.gif"></a></div>';
		if (no_thumb!=1) {
			buttons += '<div class="thumb" id="'+thumb+'"><img src="../_images/scroll_thumb.gif" width="15" height="'+thumbH+'" style="margin: '+parseInt(buttons_top+upH)+'px 0px '+parseInt(buttons_bottom+dnH)+'px 0px;"></div></div>';
		}
		
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;
		
		
		
		theRoot[count]   = document.getElementById(root);
		if (no_thumb!=1) {
			theThumb[count]  = document.getElementById(thumb);
		}
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		var thisthumbbg = document.getElementById("thumbbg"+count);	
		
		if (no_thumb!=1) {
			theThumb[count].style.left = parseInt(minX) + "px";
		}
		
		thisthumbbg.style.left = parseInt(minX) + "px";
		thisthumbbg.style.top = parseInt(minY+buttons_top+upH) + "px";
		thisthumbbg.style.height = parseInt((maxY-minY)-(buttons_top+upH+buttons_bottom+dnH)) + "px";
		thisthumbbg.style.overflowY = "hidden";
		
		thisup.style.left = parseInt(minX) + "px";
		thisdn.style.left = parseInt(minX) + "px";
		if (no_thumb!=1) {
			theThumb[count].style.border =0;
			theThumb[count].style.top = parseInt(minY) + "px";
		}
		thisup.style.top = parseInt(minY+buttons_top) + "px";
		thisdn.style.top = parseInt(maxY-buttons_bottom-dnH) + "px";
		//thisdn.style.top = 15 + "px";<img src="../images/scroller/scroll_up.gif">

		theScroll[count].load();
		
		theRoot[count].style.height = theScroll[count].clipH;
		//theRoot[count].style.overflow = "hidden";
		
		if (no_thumb!=1) {
			// the number of pixels the thumb can travel vertically (max - min)
			thumbTravel[count] = parseInt((maxY-minY)-(buttons_top+upH+buttons_bottom+dnH+thumbH));
	
			
			//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
			Drag.init(theThumb[count], null, minX, maxX, minY, thumbTravel[count]);
			
			
			// 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]));
			}
		}
		
		document.onmousewheel=function() {
			if (event.wheelDelta >= 120) {var st = theScroll[count].scrollTop - 19; theScroll[count].scrollTo(0, st, 0.1);}
			else if (event.wheelDelta <= -120) {var st = theScroll[count].scrollTop + 19; theScroll[count].scrollTo(0, st, 0.1);}
			var ny=minY+Math.round(st/ratio[count]);
			ny = Math.min(Math.max(ny, minY), maxY-buttons_top-buttons_bottom-upH-dnH-thumbH);
			theThumb[count].style.top = ny + "px";
			return false;	
		}
}	
