// ==============================================================
// 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:
// mod: 2006 ALA horizontal scroll
// ==============================================================
var theHandle = []; var theRoot = []; var theThumb = []; var theScroll = []; var thumbTravel = []; var ratio = [];

function instantiateScroller(count, id, left, top, width, height, speed, direc){
	if(document.getElementById) {
		theScroll[count] = new ypSimpleScroll(id, left, top, width, height, speed, direc);
	}
}

function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY, direc){
		var buttons;
		if(direc==0){
			buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="_res/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="_res/dn.gif" width="15" height="15"></a></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="_res/thumb.gif" width="15" height="15"></div>';
		} else {
			buttons='';
			buttons = buttons + '<div class="uph" id="up'+count+'"><a href="#" onmouseover="document.img_izq.src=\'_res/trabajos/izq-over.gif\';theScroll['+count+'].scrollWest(\''+count+'\')" onmouseout="document.img_izq.src=\'_res/trabajos/izq.gif\';theScroll['+count+'].endScroll()" onclick="return false;"><img name=img_izq src="_res/trabajos/izq.gif" width="19" height="19"></a></div>';
			buttons = buttons + '<div class="dnh" id="dn'+count+'""><a href="#" onmouseover="document.img_der.src=\'_res/trabajos/der-over.gif\';theScroll['+count+'].scrollEast(\''+count+'\')" onmouseout="document.img_der.src=\'_res/trabajos/der.gif\';theScroll['+count+'].endScroll()" onclick="return false;"><img name=img_der src="_res/trabajos/der.gif" width="19" height="19"></a></div>';
			buttons = buttons + '<div class="thumbh" id="'+thumb+'"><img name=img_bot src="_res/trabajos/cuad_blanco.gif" width="20" height="19"></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);
		
		if(direc==0){
			theThumb[count].style.left = parseInt(minX+15) + "px";
			thisup.style.left = parseInt(minX+15) + "px";
			thisdn.style.left = parseInt(minX+15) + "px";
			theThumb[count].style.border =0;
			theThumb[count].style.top = parseInt(minY) + "px";
			thisup.style.top = 0 + "px";
			thisdn.style.top = parseInt(minY+maxY) + "px";
			//thisdn.style.top = 15 + "px";
		} else {
			thisup.style.top = parseInt(maxY+17) + "px";
			thisdn.style.top = parseInt(maxY+17) + "px";
			theThumb[count].style.top = parseInt(maxY+17) + "px";
			thisup.style.left = parseInt(minX) + "px";
			thisdn.style.left = parseInt(maxX-15) + "px"	;
			theThumb[count].style.left = parseInt(minX+37) + "px";
			theThumb[count].style.border=0;
		}

		theScroll[count].load();

		if(direc==0){
			//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]));
			}
		} else {
			Drag.init(theThumb[count], null, minX+37, maxX-37-(20-2), maxY+17, maxY+17);
			thumbTravel[count] = (theThumb[count].maxX-37-(20-2)) - (theThumb[count].minX+37);
			ratio[count] = theScroll[count].scrollW / thumbTravel[count];
			theThumb[count].onDrag = function(x, y) {
				theScroll[count].jumpTo(Math.round((((x-37-(20-2)) - (theThumb[count].minX+37)) * ratio[count])+0.5),null);
			}
		}
}	

// INITIALIZER:
// ==============================================================
// ala Simon Willison http://simon.incutio.com/archive/2004/05/26/addLoadEvent
// mod: 2006 ALA horizontal scroll
// null