

// ==============================================================
// 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 = '<div class="up" id="up'+count+'"style="border:1px solid #586674;height:250px;background:#868e96;"><a href="#" onmousedown="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseup="theScroll['+count+'].endScroll()" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="hisound/webapp/img/scroller_up.png" width="15" height="17"></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmousedown="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseup="theScroll['+count+'].endScroll()" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="hisound/webapp/img/scroller_dn.png" width="15" height="17"></a></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="hisound/webapp/img/scroller_thumb.png" width="15" height="20"></div>';
    document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;

    theRoot[count]   = document.getElementById(root);
    if(document.all) {
      //theRoot[count].style.top = "-10px";
    }
    theThumb[count]  = document.getElementById(thumb);
    var thisup = document.getElementById("up"+count);
    var thisdn = document.getElementById("dn"+count);
    theThumb[count].style.left = parseInt(minX+8) + "px";
    thisup.style.left = parseInt(minX+7) + "px";
    thisdn.style.left = parseInt(minX+8) + "px";
    theThumb[count].style.border =0;
    theThumb[count].style.top = parseInt(minY) + "px";
    thisup.style.top = 0 + "px";
    thisdn.style.top = parseInt(minY+maxY+3) + "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+8, maxX+8, 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:
// ==============================================================
function initScroller()
{
  if(theScroll.length>0)
  {
    for(var i=0;i<theScroll.length;i++)
    {
      //alert(1);
      createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 17, theScroll[i].clipH-34);

      document.getElementById("scroll"+i+"Content").style.height = document.getElementById("scroll"+i+"Content").offsetHeight + "px";
      document.getElementById("scroll"+i+"Container").style.height = document.getElementById("scroll"+i+"Container").offsetHeight + "px";

      theScroll[i].jumpTo(null, 0);
    }
  }
}
