var sa_ua = navigator.userAgent;
sa_isMSIE = (navigator.appName == "Microsoft Internet Explorer");
sa_isMSIE7 = sa_isMSIE && (sa_ua.indexOf('MSIE 7') != -1);
sa_isGecko = sa_ua.indexOf('Gecko') != -1; // Will also be true on Safari
sa_isSafari = sa_ua.indexOf('Safari') != -1;
sa_isOpera = window['opera'] && opera.buildNumber ? true : false;
sa_isMac = sa_ua.indexOf('Mac') != -1;

var saarr = new Array();
var currScroll;

function scrollArea(targetdiv) {
  var param = null;
  var scrollTimer = null;
  var scroller = new Object();
  var horizTrack;
  var vertTrack;
  var horizThumb;
  var vertThumb;
  var contentdiv;
  var sframe;
  var sdiv;
  this.scrollInfo = new Object();
  this.thumbObj = new Object();

  var loadingImages = 0;

  function imgLoaded(obj, img, paramname, imgparam) {
    param[paramname] = eval("img." + imgparam);
    loadingImages--;
    if (loadingImages == 0) obj.setup();
  };

  function setImgParam(obj, imgsrc, paramname, imgparam) {
    var img = new Image();
    img.onload = function() {
      imgLoaded(obj, img, paramname, imgparam);
    }
    img.src = imgsrc;
  };

  this.setParameters = function(newparam) {
    param = newparam;
  };

  this.isVertScrollVisible = function() {
    var res = false;
    if (vertTrack != null)
      res = (vertTrack.style.display == 'block');
    return res;
  };

  this.isHorizScrollVisible = function() {
    var res = false;
    if (horizTrack != null)
      res = (horizTrack.style.display == 'block');
    return res;
  };

  this.getEventPos = function(event) {
    if (this.scrollInfo.orientation == null) return 0;
    if (sa_isMSIE || sa_isOpera) {
      if (this.scrollInfo.orientation == 'vert')
        return window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
      else
        return window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    }
    else if (sa_isGecko) {
      if (this.scrollInfo.orientation == 'vert')
        return event.clientY + window.scrollY;
      else
        return event.clientX + window.scrollX;
    }
    else {
      if (this.scrollInfo.orientation == 'vert')
        return event.clientY + window.scrollY;
      else
        return event.clientX + window.scrollX;
    }
  };

  this.scrollPosFromThumbPos = function(apos) {
    if (this.scrollInfo.orientation == 'vert')
      return parseInt(apos/(scroller.trackHeight-this.thumbObj.size_vert)*(scroller.height-this.scrollInfo.height));
    else
      return parseInt(apos/(scroller.trackWidth-this.thumbObj.size_horiz)*(scroller.width-this.scrollInfo.width));
  };

  this.thumbPosFromScrollPos = function(apos) {
    if (this.scrollInfo.orientation == 'vert')
      return parseInt(apos/(scroller.height-this.scrollInfo.height)*(scroller.trackHeight-this.thumbObj.size_vert));
    else
      return parseInt(apos/(scroller.width-this.scrollInfo.width)*(scroller.trackWidth-this.thumbObj.size_horiz));
  };

  this.initScrolling = function(mousePos) {
    this.thumbObj.cursorStart = mousePos;
    if (this.scrollInfo.orientation == 'vert') {
      this.thumbObj.elStart = parseInt(this.thumbObj.elNode.style.top, 10);
      this.thumbObj.scrollMax = scroller.trackHeight - this.thumbObj.size_vert;
      this.scrollInfo.scrollMax = scroller.height - this.scrollInfo.height;
    }
    else {
      this.thumbObj.elStart  = parseInt(this.thumbObj.elNode.style.left, 10);
      this.thumbObj.scrollMax = scroller.trackWidth - this.thumbObj.size_horiz;
      this.scrollInfo.scrollMax = scroller.width - this.scrollInfo.width;
    }
    if (isNaN(this.thumbObj.elStart)) this.thumbObj.elStart = 0;
  };

  this.dragStart = function(event,thumb) {
    this.thumbObj.elNode = thumb;
    this.scrollInfo.orientation = (thumb == vertThumb ? 'vert' : 'horiz');

    var mousePos = this.getEventPos(event);
    this.initScrolling(mousePos);

    this.thumbObj.elNode.style.zIndex = ++this.thumbObj.zIndex;
    currScroll = this;
    if (sa_isMSIE) {
      document.attachEvent('onmousemove', sa_dragGo);
      document.attachEvent('onmouseup',   sa_dragStop);
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    else if (sa_isGecko) {
      document.addEventListener('mousemove', sa_dragGo,   true);
      document.addEventListener('mouseup',   sa_dragStop, true);
      event.preventDefault();
    }
    else {
      document.addEventListener('mousemove', sa_dragGo,   true);
      document.addEventListener('mouseup',   sa_dragStop, true);
      event.preventDefault();
    }
  };

  this.adjustMousePos = function(apos) {
    if (this.scrollInfo.orientation != null) {
      var extraVert = 0;
      var extraHoriz = 0
      if (param["horizScrollPosition"] == "top")
        extraVert = param["horizTrackHeight"];
      if (param["vertScrollPosition"] == "left")
        extraHoriz = param["vertTrackWidth"];
      if (this.scrollInfo.orientation == 'vert')
        apos -= (scroller.top + scroller.arrHeight + extraVert);
      else
        apos -= (scroller.left + scroller.arrWidth + extraHoriz);
    }
    return apos;
  };

  this.scrollStart = function(event,dir) {
    if (scrollTimer == null) {
      this.scrollInfo.orientation = dir;
      var thumb = (this.scrollInfo.orientation == 'vert' ? vertThumb : horizThumb);
      this.thumbObj.elNode = thumb;

      var mousePos = this.adjustMousePos(this.getEventPos(event));
      this.initScrolling(mousePos);
      this.thumbObj.pos = this.thumbObj.elStart;

      var asize = (dir == 'vert' ? this.thumbObj.size_vert : this.thumbObj.size_horiz);
      this.scrollInfo.direction = 'none';

      if (mousePos > this.thumbObj.pos + asize) this.scrollInfo.direction = 'positive';
      else if (mousePos < this.thumbObj.pos) this.scrollInfo.direction = 'negative';

      var endoffset = (this.scrollInfo.orientation == 'vert' ? sframe.offsetTop : sframe.offsetLeft);

      this.thumbObj.endPos = mousePos - parseInt(asize/2) - endoffset;
      this.scrollInfo.endPos = this.scrollPosFromThumbPos(this.thumbObj.endPos);

      this.doStartScroll();
    }
    else if (this.scrollInfo.orientation == 'vert')
      this.scrollInfo.incVert *= 2;
    else
      this.scrollInfo.incHoriz *= 2;
  };

  this.doStartScroll = function() {
    if (this.scrollInfo.direction != 'none')
      scrollTimer = setTimeout("saarr[" + this.saindex + "].doScroll()", this.scrollInfo.speed);
  };

  this.scrollTo = function() {
    if (this.scrollInfo.orientation == 'vert') {
      this.thumbObj.elNode.style.top = this.thumbObj.pos + 'px';
      sdiv.style.top = this.scrollInfo.pos + 'px';
    }
    else {
      this.thumbObj.elNode.style.left = this.thumbObj.pos + 'px';
      sdiv.style.left = this.scrollInfo.pos + 'px';
    }
  };

  this.doScroll = function() {
    if (this.scrollInfo.direction == 'negative')
      this.scrollInfo.pos += (this.scrollInfo.orientation == 'vert' ? this.scrollInfo.incVert : this.scrollInfo.incHoriz);
    else
      this.scrollInfo.pos -= (this.scrollInfo.orientation == 'vert' ? this.scrollInfo.incVert : this.scrollInfo.incHoriz);
    this.thumbObj.pos = this.thumbPosFromScrollPos(this.scrollInfo.pos);

    var doStop = false;
    if (this.scrollInfo.pos > 0) {
      this.scrollInfo.pos = 0;
      doStop = true;
    }
    if (this.scrollInfo.pos < this.scrollInfo.scrollMax) {
      this.scrollInfo.pos = this.scrollInfo.scrollMax;
      doStop = true;
    }
    if (this.scrollInfo.direction == 'negative' && this.scrollInfo.pos > this.scrollInfo.endPos) {
      this.thumbObj.pos = this.thumbObj.endPos;
      this.scrollInfo.pos = this.scrollInfo.endPos;
      doStop = true;
    }
    if (this.scrollInfo.direction == 'positive' && this.scrollInfo.pos < this.scrollInfo.endPos) {
      this.thumbObj.pos = this.thumbObj.endPos;
      this.scrollInfo.pos = this.scrollInfo.endPos;
      doStop = true;
    }

    this.thumbObj.pos = this.thumbPosFromScrollPos(this.scrollInfo.pos);
    this.scrollTo();
    if (doStop) this.scrollStop();
    else scrollTimer = setTimeout("saarr[" + this.saindex + "].doScroll()", this.scrollInfo.speed);
  };

  this.changeScrollEnd = function(event) {
    var mousePos = this.adjustMousePos(this.getEventPos(event));

    var endoffset = (this.scrollInfo.orientation == 'vert' ? sframe.offsetTop : sframe.offsetLeft);

    if (this.scrollInfo.orientation == 'vert')
      this.thumbObj.endPos = mousePos - parseInt(this.thumbObj.size_vert/2) - endoffset;
    else
      this.thumbObj.endPos = mousePos - parseInt(this.thumbObj.size_horiz/2) - endoffset;
    this.scrollInfo.endPos = this.scrollPosFromThumbPos(this.thumbObj.endPos);
  };

  this.jumpTo = function(dir,endPos) {
    if (dir == 'vertical') {
      this.scrollInfo.orientation = 'vert';
      this.thumbObj.elNode = vertThumb;
    }
    else {
      this.scrollInfo.orientation = 'horiz';
      this.thumbObj.elNode = horizThumb;
    }

    this.initScrolling(0);
    if (endPos < this.scrollInfo.scrollMax && (dir == 'horiz' && horizTrack.style.display == 'block' || dir == 'vert' && vertTrack.style.display == 'block'))
      endPos = this.scrollInfo.scrollMax;

    this.thumbObj.pos = this.thumbPosFromScrollPos(endPos);
    this.scrollInfo.pos = endPos;
    this.scrollTo();
  };

  this.stepTo = function(dir,endPos) {
    if (dir == 'up' || dir == 'down') {
      this.scrollInfo.orientation = 'vert';
      this.thumbObj.elNode = vertThumb;
    }
    else {
      this.scrollInfo.orientation = 'horiz';
      this.thumbObj.elNode = horizThumb;
    }

    this.scrollInfo.pos = this.scrollInfo.direction = (dir == 'up' || dir == 'down' ? this.scrollInfo.vertPos : this.scrollInfo.horizPos);
    this.scrollInfo.direction = (dir == 'up' || dir == 'left' ? 'negative' : 'positive');

    this.initScrolling(0);
    this.thumbObj.endPos = this.thumbPosFromScrollPos(endPos);
    this.scrollInfo.endPos = endPos;


    this.scrollInfo.incVert = scroller.stepIncVert;
    this.scrollInfo.incHoriz = scroller.stepIncHoriz;
    this.doStartScroll();
  };

  this.getChildNode = function(idx,aNode) {
    var found = -1;
    var count = 0;
    while (found < idx && count < aNode.childNodes.length) {
      if (aNode.childNodes[count].tagName) found++;
      count++;
    }
    return aNode.childNodes[count-1];
  };

  this.doStep = function(dir) {
    var scrollTo = null;
    var step = (dir == 'left' || dir == 'right' ? parseInt(scroller.width*scroller.horizStepSize/100) : parseInt(scroller.height*scroller.vertStepSize/100));
    var apos = (dir == 'left' || dir == 'right' ? this.scrollInfo.horizPos : this.scrollInfo.vertPos);
    if (dir == 'left' || dir == 'up') scrollTo = apos + step;
    else scrollTo = apos - step;
    if (scrollTo != null) this.stepTo(dir, scrollTo);
  };

  this.scrollStop = function() {
    clearTimeout(scrollTimer);
    scrollTimer = null;
    this.resetSpeed();
    if (this.scrollInfo.orientation == 'vert')
      this.scrollInfo.vertPos = this.scrollInfo.pos;
    else
      this.scrollInfo.horizPos = this.scrollInfo.pos;
  };

  this.resetSpeed = function() {
    this.scrollInfo.incVert = param["vertScrollSpeed"];
    if (this.scrollInfo.incVert == 0) this.scrollInfo.incVert = 1;
    this.scrollInfo.incHoriz = param["horizScrollSpeed"];
    if (this.scrollInfo.incHoriz == 0) this.scrollInfo.incHoriz = 1;
  };

  this.setContent = function(html, keepscrollpos) {
    contentdiv.innerHTML = html;
    this.contentChanged(keepscrollpos);
  };

  this.contentChanged = function(keepscrollpos) {
    sframe.style.width = ''
    sframe.style.height = ''
    sframe.style.overflow='visible';
    sframe.style.position='relative';
    sdiv.style.position='relative';
    this.initScrollers();
    if (!keepscrollpos && param["horizScroller"]) this.jumpTo("horizontal", 0);
    if (!keepscrollpos && param["vertScroller"]) this.jumpTo("vertical", 0);
  };


  this.getAbsoluteTop = function(obj) {
    atop = 0;
    while (obj.offsetParent != null) {
      obj = obj.offsetParent;
      atop += obj.offsetTop;
    }
    return atop;
  };

  this.getAbsoluteLeft = function(obj) {
    aleft = 0;
    while (obj.offsetParent != null) {
      obj = obj.offsetParent;
      aleft += obj.offsetLeft;
    }
    return aleft;
  };

  this.initScrollers = function() {
    var swidth = sdiv.offsetWidth;
    if (sa_isMSIE) {
      sframe.style.position = "absolute";
      swidth = sdiv.offsetWidth;
      sframe.style.position = "relative";
    }

    scroller.top = this.getAbsoluteTop(sframe);

    scroller.left = this.getAbsoluteLeft(sframe);

    if (sa_isGecko) {
      if (sa_isMac) {
        var scrwidth1 = document.body.scrollWidth;
        sframe.style.overflow='hidden';
        var scrwidth2 = document.body.scrollWidth;
        sframe.style.overflow='visible';
        if (scrwidth1 > scrwidth2)
          swidth = document.body.scrollWidth-scroller.left;
      }
      else {
        if (swidth + scroller.left >= window.innerWidth)
          swidth = document.body.scrollWidth-scroller.left;
      }
    }
    this.scrollInfo.width = swidth;
    sframe.style.overflow='hidden';
    scroller.width = param["width"];
    sframe.style.position='absolute';
    sdiv.style.position='absolute';
    sframe.style.width = scroller.width + "px";
    sframe.style.height = scroller.height + "px";

    this.scrollInfo.height = sdiv.offsetHeight;
    scroller.stepIncVert = scroller.vertStepSpeed;
    if (scroller.stepIncVert == 0)
      scroller.stepIncVert = 1;
    scroller.stepIncHoriz = scroller.horizStepSpeed;
    if (scroller.stepIncHoriz == 0) scroller.stepIncHoriz = 1;
    this.resetSpeed();
    if (param["vertScroller"]) {
      if (vertTrack != null) {
        if(param["autoHide"])
          vertTrack.style.display = (this.scrollInfo.height <= param["height"] ? 'none' : 'block');
        else
          vertTrack.style.display = 'block';
      }
    }
    if (param["horizScroller"]) {
      if (horizTrack != null) {
        if(param["autoHide"])
          horizTrack.style.display = (this.scrollInfo.width <= param["width"] ? 'none' : 'block');
        else
          horizTrack.style.display = 'block';
      }
    }
    targetdiv.style.visibility = "visible";
  };

  this.getCssStyle = function(id, className, styleelem) {
    var classes = className.split(" ");
    var cssRules = (document.all ? "rules" : "cssRules");
    var res = "";
    for (var i=0; i < document.styleSheets.length && res.length == 0; i++){
      for (var j=0; j < document.styleSheets[i][cssRules].length && res.length == 0; j++) {
        var sel = document.styleSheets[i][cssRules][j].selectorText;
        if (sel == "#" + id)
          res = document.styleSheets[i][cssRules][j].style[styleelem];
        else {
          for (var k=0; k < classes.length; k++)
            if (sel == "." + classes[k]) res = document.styleSheets[i][cssRules][j].style[styleelem];
        }
      }
    }
    return res;
  };

  this.setupHtml = function() {
    var currindex = this.saindex;

    contentdiv = document.createElement("DIV");
    contentdiv.style.position = "relative";
    contentdiv.innerHTML = targetdiv.innerHTML;

    targetdiv.innerHTML = "";
    targetdiv.style.width = (param["vertScroller"] ? param["width"] + param["vertTrackWidth"] : param["width"]) + "px";
    targetdiv.style.height = (param["horizScroller"] ? param["height"] + param["horizTrackHeight"] : param["height"]) + "px";

    sframe = document.createElement("DIV");
    sframe.style.overflow = "hidden";
    sframe.style.position = "relative";
    targetdiv.appendChild(sframe);

    sdiv = document.createElement("DIV");
    sdiv.style.position = "absolute";
    sframe.appendChild(sdiv);

    sdiv.appendChild(contentdiv);

    if (param["horizScroller"]) {
      horizTrack = document.createElement("DIV");
      horizTrack.style.position = "absolute";
      horizTrack.style.background = "url(" + param["imagepath"] + "/horiz_track.gif)";
      horizTrack.style.display = "block";
      horizTrack.style.marginTop = (param["horizScrollPosition"] == "top" ? String(-param["horizTrackHeight"]) + "px" : String(param["height"]) + "px");
      horizTrack.style.width = String(param["width"]) + "px";
      horizTrack.style.height = String(param["horizTrackHeight"]) + "px";

      var leftarr = document.createElement("DIV");
      leftarr.style.position = "absolute";
      leftarr.innerHTML = "<a onfocus='this.blur()' href='javascript:saarr[" + this.saindex + "].doStep(\"left\")'><img src='" + param["imagepath"] + "/scroll_left.gif' alt='' style='border:0;display:block' /></a>";
      horizTrack.appendChild(leftarr);

      var track = document.createElement("DIV");
      track.style.position = "absolute";
      track.style.marginLeft = String(param["leftArrWidth"]) + "px";
      track.style.width = String(param["width"] - param["leftArrWidth"] - param["rightArrWidth"]) + "px";
      track.style.height = String(param["horizTrackHeight"]) + "px";
      track.onmouseout = function() { saarr[currindex].scrollStop(); };
      track.onmousemove = function(event) { saarr[currindex].changeScrollEnd(event); };
      track.onclick = function(event) { saarr[currindex].scrollStart(event, 'horiz'); };
      horizTrack.appendChild(track);

      horizThumb = document.createElement("DIV");
      horizThumb.style.position = "absolute";
      horizThumb.style.zIndex = "1";
      horizThumb.onmouseover = function() { saarr[currindex].scrollStop(); };
      var hthumb = horizThumb;
      horizThumb.onmousedown = function(event) { saarr[currindex].dragStart(event, hthumb); };
      horizThumb.innerHTML = "<a onfocus='this.blur()' href='javascript:void(0)'><img src='" + param["imagepath"] + "/horiz_slider.gif' alt='' style='border:0;display:block' /></a>";
      track.appendChild(horizThumb);

      var rightarr = document.createElement("DIV");
      rightarr.style.position = "absolute";
      rightarr.style.marginLeft = String(param["width"] - param["leftArrWidth"]) + "px";
      rightarr.innerHTML = "<a onfocus='this.blur()' href='javascript:saarr[" + this.saindex + "].doStep(\"right\")'><img src='" + param["imagepath"] + "/scroll_right.gif' alt='' style='border:0;display:block' /></a>";
      horizTrack.appendChild(rightarr);

      targetdiv.appendChild(horizTrack);
    }

    if (param["vertScroller"]) {
      vertTrack = document.createElement("DIV");
      vertTrack.style.position = "absolute";
      vertTrack.style.background = "url(" + param["imagepath"] + "/vert_track.gif)";
      vertTrack.style.display = "block";
      vertTrack.style.marginLeft = (param["vertScrollPosition"] == "left" ? String(-param["vertTrackWidth"]) + "px" : String(param["width"]) + "px");
      vertTrack.style.width = String(param["vertTrackWidth"]) + "px";
      vertTrack.style.height = String(param["height"]) + "px";

      var uparr = document.createElement("DIV");
      uparr.style.position = "absolute";
      uparr.innerHTML = "<a onfocus='this.blur()' href='javascript:saarr[" + this.saindex + "].doStep(\"up\")'><img src='" + param["imagepath"] + "/scroll_up.gif' alt='' style='border:0;display:block' /></a>";
      vertTrack.appendChild(uparr);

      var track = document.createElement("DIV");
      track.style.position = "absolute";
      track.style.marginTop = String(param["upArrHeight"]) + "px";
      track.style.height = String(param["height"] - param["upArrHeight"] - param["downArrHeight"]) + "px";
      track.style.width = String(param["vertTrackWidth"]) + "px";
      track.onmouseout = function() { saarr[currindex].scrollStop(); };
      track.onmousemove = function(event) { saarr[currindex].changeScrollEnd(event); };
      track.onclick = function(event) { saarr[currindex].scrollStart(event, 'vert'); };
      vertTrack.appendChild(track);

      vertThumb = document.createElement("DIV");
      vertThumb.style.position = "absolute";
      vertThumb.style.zIndex = "1";
      vertThumb.onmouseover = function() { saarr[currindex].scrollStop(); };
      var vthumb = vertThumb;
      vertThumb.onmousedown = function(event) { saarr[currindex].dragStart(event, vthumb); };
      vertThumb.innerHTML = "<a onfocus='this.blur()' href='javascript:void(0)'><img src='" + param["imagepath"] + "/vert_slider.gif' style='border:0;display:block' alt=''/></a>";
      track.appendChild(vertThumb);

      var downarr = document.createElement("DIV");
      downarr.style.position = "absolute";
      downarr.style.marginTop = String(param["height"] - param["downArrHeight"]) + "px";
      downarr.innerHTML = "<a onfocus='this.blur()' href='javascript:saarr[" + this.saindex + "].doStep(\"down\")'><img src='" + param["imagepath"] + "/scroll_down.gif' style='border:0;display:block' /></a>";
      vertTrack.appendChild(downarr);

      targetdiv.appendChild(vertTrack);
    }
  };

  this.setupParams = function() {
    if (!param) param = new Object();

    if (typeof(targetdiv) != "object")
      targetdiv = document.getElementById(targetdiv);

    if (!param["horizStartPos"]) param["horizStartPos"] = 0;
    if (!param["vertStartPos"]) param["vertStartPos"] = 0;
    if (!param["horizStepSize"]) param["horizStepSize"] = 90;
    if (!param["vertStepSize"]) param["vertStepSize"] = 90;
    if (!param["vertStepSpeed"]) param["vertStepSpeed"] = 30;
    if (!param["horizStepSpeed"]) param["horizStepSpeed"] = 30;
    if (!param["horizScrollPosition"]) param["horizScrollPosition"] = 'bottom';
    if (!param["vertScrollPosition"]) param["vertScrollPosition"] = 'right';
    if (!param["vertScrollSpeed"]) param["vertScrollSpeed"] = 2;
    if (!param["horizScrollSpeed"]) param["horizScrollSpeed"] = 2;
    if (!param["vertScroller"]) param["vertScroller"] = true;
    if (!param["horizScroller"]) param["horizScroller"] = false;
    if (!param["autoHide"]) param["autoHide"] = true;
    if (!param["imagepath"]) param["imagepath"] = 'scrollarea';

    if (!param["width"] || param["width"].length == 0) {
      if (targetdiv.style.width.length > 0)
        param["width"] = parseInt(targetdiv.style.width.substring(0, targetdiv.style.width.length - 2));
      else {
        var w = this.getCssStyle(targetdiv.id, targetdiv.className, "width");
        if (w.length > 0) param["width"] = parseInt(w.substring(0, w.length - 2));
        else param["width"] = 200;
      }
    }

    if (!param["height"] || param["height"].length == 0) {
      if (targetdiv.style.height.length > 0)
        param["height"] = parseInt(targetdiv.style.height.substring(0, targetdiv.style.height.length - 2));
      else {
        var h = this.getCssStyle(targetdiv.id, targetdiv.className, "height");
        if (h.length > 0) param["height"] = parseInt(h.substring(0, h.length - 2));
        else param["height"] = 200;
      }
    }

    if (param["vertScroller"]) loadingImages += 4;
    if (param["horizScroller"]) loadingImages += 4;
    var obj = this;
    if (param["vertScroller"]) {
      setImgParam(obj, param["imagepath"] + "/scroll_up.gif", "upArrHeight", "height");
      setImgParam(obj, param["imagepath"] + "/scroll_down.gif", "downArrHeight", "height");
      setImgParam(obj, param["imagepath"] + "/vert_slider.gif", "vertThumbLength", "height");
      setImgParam(obj, param["imagepath"] + "/vert_track.gif", "vertTrackWidth", "width");
    }
    if (param["horizScroller"]) {
      setImgParam(obj, param["imagepath"] + "/scroll_left.gif", "leftArrWidth", "width");
      setImgParam(obj, param["imagepath"] + "/scroll_right.gif", "rightArrWidth", "width");
      setImgParam(obj, param["imagepath"] + "/horiz_slider.gif", "horizThumbLength", "width");
      setImgParam(obj, param["imagepath"] + "/horiz_track.gif", "horizTrackHeight", "height");
    }
  };


  this.setupObjects = function() {
    scroller.width = param["width"];
    scroller.height = param["height"];
    scroller.trackWidth = param["width"] - param["leftArrWidth"] - param["rightArrWidth"];
    scroller.trackHeight = param["height"] - param["upArrHeight"] - param["downArrHeight"];
    scroller.arrWidth = param["leftArrWidth"];
    scroller.arrHeight = param["upArrHeight"];
    scroller.vertStepSize = param["vertStepSize"];
    scroller.horizStepSize = param["horizStepSize"];
    scroller.vertStepSpeed = param["vertStepSpeed"];
    scroller.horizStepSpeed = param["horizStepSpeed"];
    this.scrollInfo.speed = 1;
    this.scrollInfo.pos = 0;
    this.scrollInfo.vertPos = 0;
    this.scrollInfo.horizPos = 0;

    this.thumbObj.zIndex = 0;
    this.thumbObj.pos = 0;
    this.thumbObj.size_vert = param["vertThumbLength"];
    this.thumbObj.size_horiz = param["horizThumbLength"];
  };

  this.setup = function() {
    this.setupObjects();
    this.setupHtml();
    this.initScrollers();

    this.thumbObj.elStart = 0;
    if (param["vertStartPos"] != 0) {
      var vertpos = -parseInt(scroller.height*param["vertStartPos"]/100);
      this.jumpTo("vertical", vertpos);
      this.scrollInfo.pos = vertpos;
    }
    if (param["horizStartPos"] != 0) {
      var horizpos = -parseInt(scroller.width*param["horizStartPos"]/100);
      this.jumpTo("horizontal", horizpos);
      this.scrollInfo.pos = horizpos;
    }
  };

  this.saindex = saarr.length;
  saarr.push(this);
};

function sa_init() {
  var divs = document.getElementsByTagName("DIV");
  for (var i=0; i < divs.length; i++)
    if (divs[i].className.indexOf("sa_scrollarea") >= 0)
      new scrollArea(divs[i]);

  for (var i=0; i < saarr.length; i++)
    saarr[i].setupParams();
};

function sa_dragGo(event) {
  var mousePos = currScroll.getEventPos(event);
  currScroll.thumbObj.pos = currScroll.thumbObj.elStart + mousePos - currScroll.thumbObj.cursorStart;

  if (currScroll.thumbObj.pos < 0) currScroll.thumbObj.pos = 0;
  if (currScroll.thumbObj.pos > currScroll.thumbObj.scrollMax) currScroll.thumbObj.pos = currScroll.thumbObj.scrollMax;

  currScroll.scrollInfo.pos = currScroll.scrollPosFromThumbPos(currScroll.thumbObj.pos);
  currScroll.scrollTo();

  if (sa_isMSIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else if (sa_isGecko) {
    event.preventDefault();
  }
  else {
    event.preventDefault();
  }
};

function sa_dragStop(event) {
  if (sa_isMSIE) {
    document.detachEvent('onmousemove', sa_dragGo);
    document.detachEvent('onmouseup',   sa_dragStop);
  }
  else if (sa_isGecko) {
    document.removeEventListener('mousemove', sa_dragGo,   true);
    document.removeEventListener('mouseup',   sa_dragStop, true);
  }
  else {
    document.removeEventListener('mousemove', sa_dragGo,   true);
    document.removeEventListener('mouseup',   sa_dragStop, true);
  }
};


if (window.attachEvent)
  window.attachEvent("onload", sa_init);
else
  window.addEventListener("load", sa_init, false);