

// ==============================================================
// 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){
	if(document.getElementById) {
		theScroll[count] = new ypSimpleScroll(id, left, top, width, height, speed);
	}
}

function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY){
		var buttons = '';
		buttons += '<div class="up" id="up'+count+'" ';
		buttons +=   'onmouseover ="document.getElementById(\'imgup'+count+'\').src=\'layout/scroll/up_over.gif\'" ';
		buttons +=   'onmouseout  ="document.getElementById(\'imgup'+count+'\').src=\'layout/scroll/up.gif\'; theScroll['+count+'].endScroll();" ';
		buttons +=   'onmousedown ="document.getElementById(\'imgup'+count+'\').src=\'layout/scroll/up_over.gif\'; theScroll['+count+'].scrollNorth(\''+count+'\');" ';
		buttons +=   'onmouseup   ="document.getElementById(\'imgup'+count+'\').src=\'layout/scroll/up.gif\'; theScroll['+count+'].endScroll();">';
		buttons += '<img id="imgup'+count+'" src="layout/scroll/up.gif" width="19" height="9"></div>';
		buttons += '<div class="dn" id="dn'+count+'" ';
		buttons +=   'onmouseover ="document.getElementById(\'imgdn'+count+'\').src=\'layout/scroll/dn_over.gif\'" ';
		buttons +=   'onmouseout  ="document.getElementById(\'imgdn'+count+'\').src=\'layout/scroll/dn.gif\'; theScroll['+count+'].endScroll();" ';
		buttons +=   'onmousedown ="document.getElementById(\'imgdn'+count+'\').src=\'layout/scroll/dn_over.gif\'; theScroll['+count+'].scrollSouth(\''+count+'\');" ';
		buttons +=   'onmouseup   ="document.getElementById(\'imgdn'+count+'\').src=\'layout/scroll/dn.gif\'; theScroll['+count+'].endScroll();">';
		buttons += '<img id="imgdn'+count+'" src="layout/scroll/dn.gif" width="19" height="9"></div>';
		buttons += '<div class="thumb" id="'+thumb+'" ';
		buttons +=   'onmouseover ="document.getElementById(\'imgthumb'+count+'\').src=\'layout/scroll/thumb_over.gif\'" ';
		buttons +=   'onmouseout  ="document.getElementById(\'imgthumb'+count+'\').src=\'layout/scroll/thumb.gif\'" ';
		buttons +=   'onclick     ="document.getElementById(\'imgthumb'+count+'\').src=\'layout/scroll/thumb_over.gif\'" ';
		buttons +=   'ondblclick  ="document.getElementById(\'imgthumb'+count+'\').src=\'layout/scroll/thumb_over.gif\'" ';
		buttons +=   'onmouseup   ="document.getElementById(\'imgthumb'+count+'\').src=\'layout/scroll/thumb.gif\'"><img id="imgthumb'+count+'" src="layout/scroll/thumb.gif" width="19" height="12"></div>';
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;

		theRoot[count]   = document.getElementById(root);
		theThumb[count]  = document.getElementById(thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);

		theThumb[count].style.left = parseInt(minX) + "px";
		thisup.style.left = parseInt(minX) + "px";
		thisdn.style.left = parseInt(minX) + "px";

		theThumb[count].style.border =0;
		if (scrollTop) theThumb[count].style.top = scrollTop; else theThumb[count].style.top = parseInt(minY) + "px";
		
		if (document.all) thisup.style.top = 0 + "px"; else thisup.style.top = -2 + "px";

		if (document.all) thisdn.style.top = parseInt(minY+maxY+2) + "px"; else thisdn.style.top = parseInt(minY+maxY) + "px";
		//thisdn.style.top = 15 + "px";

		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();
         }
      }
   }
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, 11, theScroll[i].clipH-22);
		}
	}
})
