

// ==============================================================
// 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){

// compensate for non-Firefox 
	var isNotFirefox = this.navigator.userAgent.indexOf("Firefox") == -1;	//@pjc
	if( isNotFirefox ) {													//@pjc
		top -= 20;
	}

	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 = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="Images/up.gif" width="15" height="15"></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="Images/dn.gif" width="15" height="15"></a></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="Images/thumb.gif" width="15" height="15"></div>';
		
		// new scroll jpgs @pjc
		var buttons='<div class="up" id="up'+count+'">' + 
						'<a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+
								count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;">' + 
							'<img src="Images/ScrollArrowUp.jpg" width="19" height="18"></a></div>' + 
					'<div class="dn"  id="dn'+count+'"">' + 
						'<a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+
								count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;">' + 
							'<img src="Images/ScrollArrowDown.jpg" width="19" height="18"></a></div>' + 
					'<div class="thumbArea" id="'+thumb+'ThumbArea">' + 
							'</div>' +
					'<div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;">' + 
							'<img src="Images/ScrollMovingBox.jpg" width="19" height="14"></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);
		theRoot[count].style.visibility="visible";				//@pjc
		thisup.style.left = parseInt(minX+15) + "px";			//@pjc
		thisdn.style.left = thisup.style.left;					//@pjc
		theThumb[count].style.left = thisup.style.left;			//@pjc
		theThumb[count].style.border =0;
		theThumb[count].style.top = parseInt(minY) + "px";
		thisup.style.top = parseInt(minY-20) + "px";			//@pjc
		thisdn.style.top = parseInt(maxY+16) + "px";			//@pjc
		thisup.style.position = "absolute";
		thisdn.style.position = "absolute";		
		//thisdn.style.top = 15 + "px";
		
		// new thumb area @pjc
		var thisThumbArea = document.getElementById(thumb+"ThumbArea");
		thisThumbArea.style.left = parseInt(minX+15+1) + "px";;
		thisThumbArea.style.top = parseInt(minY-20+17) + "px";
		thisThumbArea.style.height = parseInt( (maxY+16-0)-(minY-20+17) ) + "px";
		thisThumbArea.style.position = "absolute";
		
		theScroll[count].load();

		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		Drag.init(theThumb[count], null, minX+15, maxX+15, 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].clipLeft-12	//@pjc
						  ,theScroll[i].clipW + theScroll[i].clipLeft-12	//@pjc
						  ,theScroll[i].clipTop + 20						//@pjc
						  ,theScroll[i].clipTop + theScroll[i].clipH-30);	//@pjc
		}
	}
}) 
