

// ==============================================================
// 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 leftButton = '<div class="left" id="left'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollWest(\''+count+'\'); " onmouseout="theScroll['+count+'].endScroll();" onclick="return false;"><img name="left" src="scroll/scroll_left.gif" width="50" height="50"></a></div>';
		
		var rightButton = '<div class="right"  id="right'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollEast(\''+count+'\');" onmouseout="theScroll['+count+'].endScroll();" onclick="return false;"><img name="right" src="scroll/scroll_right.gif" width="50" height="50"></a></div></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;">';
	
		document.getElementById(root).innerHTML = leftButton + document.getElementById(root).innerHTML +rightButton+'</div>';
		
		
		/*
		var buttons = '<div style="position: relative; top: 500px"><div class="left" id="left'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollWest(\''+count+'\'); " onmouseout="theScroll['+count+'].endScroll();" onclick="return false;"><img name="left" src="scroll/scroll_up.jpg" width="20" height="20"></a></div><div class="right"  id="right'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollEast(\''+count+'\');" onmouseout="theScroll['+count+'].endScroll();" onclick="return false;"><img name="right" src="scroll/scroll_down.jpg" width="20" height="20"></a></div></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="scroll/spacer.gif" width="20" height="20"></div>';
		
		document.getElementById(root).innerHTML = document.getElementById(root).innerHTML + buttons;

		*/


		theRoot[count]   = document.getElementById(root);
		theThumb[count]  = document.getElementById(thumb);
		/*
		var thisleft = document.getElementById("left"+count);
		var thisright = document.getElementById("right"+count);
		theThumb[count].style.left = parseInt(minX+22) + "px";
		thisleft.style.left = parseInt(minX-28) + "px";
		thisright.style.left = parseInt(minX-28) + "px";
		theThumb[count].style.border =0;
		theThumb[count].style.top = parseInt(minY) + "px";
		thisleft.style.top = -20 + "px";
		thisright.style.top = parseInt(minY+maxY+19) + "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+20, maxX+20, 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, 20, theScroll[i].clipH-20);
		}
	}
}) 
