/* $Date: 2009-07-30 03:54:27 +0200 (to, 30 jul 2009) $    $Revision: 5131 $ */
var sa_ua = navigator.userAgent;
var sa_isMSIE = (navigator.appName == "Microsoft Internet Explorer");
var sa_isMSIE7 = sa_isMSIE && (sa_ua.indexOf('MSIE 7') != -1);
var sa_isGecko = sa_ua.indexOf('Gecko') != -1; // Will also be true on Safari
var sa_isSafari = sa_ua.indexOf('Safari') != -1;
var sa_isOpera = window['opera'] && opera.buildNumber ? true : false;
var sa_isMac = sa_ua.indexOf('Mac') != -1;

var saarr = new Array();
var currScroll;

function scrollArea(targetdiv, param, manualsetup) {
  var scrollTimer = null;
  this.scroller = new Object();
  var horizThumb;
  var vertThumb;
  var sframe;
  var sdiv;
  this.param = param;
  this.manualsetup = manualsetup;
  this.scrollInfo = new Object();
  this.thumbObj = new Object();
  var loadingImages = 0;
  this.setupdone = false;

  function imgLoaded(obj, img, paramname, imgparam) {
    obj.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.isVertScrollVisible = function() {
    var res = false;
    if (this.vertTrack != null)
      res = (this.vertTrack.style.display == 'block');
    return res;
  };

  this.isHorizScrollVisible = function() {
    var res = false;
    if (this.horizTrack != null)
      res = (this.horizTrack.style.display == 'block');
    return res;
  };

  this.getCssParam = function(elem, styleelem, asNumber) {
    if (elem.style[styleelem] && elem.style[styleelem].length > 0)
      return elem.style[styleelem];
    else {
      var classes = elem.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 == "#" + elem.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];
          }
        }
      }
      if (asNumber) {
        if (res.length == 0) return 0;
        return parseInt(res.substring(0, res.length-2));
      }
      else
        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/(this.scroller.trackHeight-this.thumbObj.size_vert)*(this.scroller.height-this.scrollInfo.height));
    else
      return parseInt(apos/(this.scroller.trackWidth-this.thumbObj.size_horiz)*(this.scroller.width-this.scrollInfo.width));
  };

  this.thumbPosFromScrollPos = function(apos) {
    if (this.scrollInfo.orientation == 'vert')
      return parseInt(apos/(this.scroller.height-this.scrollInfo.height)*(this.scroller.trackHeight-this.thumbObj.size_vert));
    else
      return parseInt(apos/(this.scroller.width-this.scrollInfo.width)*(this.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 = this.scroller.trackHeight - this.thumbObj.size_vert;
      this.scrollInfo.scrollMax = this.scroller.height - this.scrollInfo.height;
    }
    else {
      this.thumbObj.elStart  = parseInt(this.thumbObj.elNode.style.left, 10);
      this.thumbObj.scrollMax = this.scroller.trackWidth - this.thumbObj.size_horiz;
      this.scrollInfo.scrollMax = this.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 (this.param["horizScrollPosition"] == "top")
        extraVert = this.param["horizTrackHeight"];
      if (this.param["vertScrollPosition"] == "left")
        extraHoriz = this.param["vertTrackWidth"];
      if (this.scrollInfo.orientation == 'vert')
        apos -= (this.scroller.top + this.scroller.arrHeight + extraVert);
      else
        apos -= (this.scroller.left + this.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' && this.horizTrack.style.display == 'block' || dir == 'vert' && this.vertTrack.style.display == 'block'))
      endPos = this.scrollInfo.scrollMax;

    this.thumbObj.pos = this.thumbPosFromScrollPos(endPos);
    this.scrollInfo.pos = endPos;
    this.scrollTo();
  };

  this.jumpToEnd = function(dir) {
    if (dir == 'vertical' && this.scrollInfo.height > this.param["height"])
      this.jumpTo(dir, this.scrollInfo.scrollMax);
    else if (dir == 'horizontal' && this.scrollInfo.width > this.param["width"])
      this.jumpTo(dir, this.scrollInfo.scrollMax);
  };

  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 = this.scroller.stepIncVert;
    this.scrollInfo.incHoriz = this.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(this.scroller.width*this.scroller.horizStepSize/100) : parseInt(this.scroller.height*this.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 = this.param["vertScrollSpeed"];
    if (this.scrollInfo.incVert == 0) this.scrollInfo.incVert = 1;
    this.scrollInfo.incHoriz = this.param["horizScrollSpeed"];
    if (this.scrollInfo.incHoriz == 0) this.scrollInfo.incHoriz = 1;
  };

  this.setContent = function(html, keepscrollpos) {
    var thisref = this;
    if (!this.setupdone) {
      setTimeout(function(){thisref.setContent(html, keepscrollpos)}, 300);
      return;
    }
    this.contentdiv.innerHTML = html;
    this.contentChanged(keepscrollpos);
  };

  this.getContent = function() {
    return this.contentdiv.innerHTML;
  };

  this.contentChanged = function(keepscrollpos) {
    try {
      if (!this.setupdone) return;
      sframe.style.width = ''
      sframe.style.height = ''
      sframe.style.overflow='visible';
      sdiv.style.position='relative';

      this.initScrollers();
      if (!keepscrollpos && this.param["horizScroller"]) this.jumpTo("horizontal", 0);
      if (!keepscrollpos && this.param["vertScroller"]) this.jumpTo("vertical", 0);
    }
    catch(e) {}
  };


  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 (swidth == 0) return;
    if (sa_isMSIE) {
      sframe.style.position = "absolute";
      swidth = sdiv.offsetWidth;
      sframe.style.position = "relative";
    }

    this.scroller.top = this.getAbsoluteTop(sframe);

    this.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-this.scroller.left;
      }
      else {
        if (swidth + this.scroller.left >= window.innerWidth)
          swidth = document.body.scrollWidth-this.scroller.left;
      }
    }
    this.scrollInfo.width = swidth;
    sframe.style.overflow='hidden';
    this.scroller.width = this.param["width"];
    sframe.style.position='absolute';
    sdiv.style.position='absolute';
    sframe.style.width = this.scroller.width + "px";
    sframe.style.height = this.scroller.height + "px";

    this.scrollInfo.height = sdiv.offsetHeight;
    this.scroller.stepIncVert = this.scroller.vertStepSpeed;
    if (this.scroller.stepIncVert == 0)
      this.scroller.stepIncVert = 1;
    this.scroller.stepIncHoriz = this.scroller.horizStepSpeed;
    if (this.scroller.stepIncHoriz == 0) this.scroller.stepIncHoriz = 1;
    this.resetSpeed();
    if (this.param["vertScroller"]) {
      if (this.vertTrack != null) {
        if(this.param["autoHide"])
          this.vertTrack.style.display = (this.scrollInfo.height <= this.param["height"] ? 'none' : 'block');
        else
          this.vertTrack.style.display = 'block';
      }

      var cw = this.getCssParam(targetdiv, "width");
      if (this.vertTrack.style.display == 'block') {
        var w = parseInt(cw) - this.param["vertTrackWidth"];
        this.contentdiv.style.width = String(w < 0 ? 0 : w) + "px";
        this.scrollInfo.height = sdiv.offsetHeight;
      }
      else {
        this.contentdiv.style.width = cw;
      }

    }
    if (this.param["horizScroller"]) {
      if (this.horizTrack != null) {
        if(this.param["autoHide"])
          this.horizTrack.style.display = (this.scrollInfo.width <= this.param["width"] ? 'none' : 'block');
        else
          this.horizTrack.style.display = 'block';
      }

      var ch = this.getCssParam(targetdiv, "height");
      if (this.horizTrack.style.display == 'block') {
        var h = parseInt(ch) - this.param["horizTrackHeight"];
        this.contentdiv.style.height = String(h < 0 ? 0 : h) + "px";
        this.scrollInfo.width = sdiv.offsetWidth;
      }
      else {
        this.contentdiv.style.height = ch;
      }

    }
    targetdiv.style.visibility = "visible";
  };

  this.setupHtml = function() {
    var currindex = this.saindex;

    this.contentdiv = document.createElement("DIV");
    this.contentdiv.style.position = "relative";

    while (targetdiv.firstChild) {
      var anode = targetdiv.firstChild;
      targetdiv.removeChild(anode);
      this.contentdiv.appendChild(anode);
    }
    this.contentdiv.style.width = (this.param["horizScroller"] && sa_isMSIE ? this.getCssParam(targetdiv, "width") : "auto");
    this.contentdiv.style.height = "auto";
//    targetdiv.style.width = (this.param["vertScroller"] ? this.param["width"] + this.param["vertTrackWidth"] : this.param["width"]) + "px";
//    targetdiv.style.height = (this.param["horizScroller"] ? this.param["height"] + this.param["horizTrackHeight"] : this.param["height"]) + "px";
    targetdiv.style.width = this.param["width"] + "px";
    targetdiv.style.height = this.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(this.contentdiv);

    if (this.param["horizScroller"]) {
      this.horizTrack = document.createElement("DIV");
      this.horizTrack.className = "sa_horiztrack";
      this.horizTrack.style.position = "absolute";
      this.horizTrack.style.background = "url(" + this.param["imagepath"] + "/horiz_track.gif)";
      this.horizTrack.style.display = "block";
      this.horizTrack.style.marginTop = (this.param["horizScrollPosition"] == "top" ? "0" : String(this.param["height"]-this.param["horizTrackHeight"]) + "px");
      this.horizTrack.style.width = String(this.param["width"]) + "px";
      this.horizTrack.style.height = String(this.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='" + this.param["imagepath"] + "/scroll_left.gif' alt='' style='border:0;display:block' /></a>";
      this.horizTrack.appendChild(leftarr);

      var track = document.createElement("DIV");
      track.style.position = "absolute";
      track.style.marginLeft = String(this.param["leftArrWidth"]) + "px";
      var w = this.param["width"] - this.param["leftArrWidth"] - this.param["rightArrWidth"];
      track.style.width = String(w < 0 ? 0 : w) + "px";
      track.style.height = String(this.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'); };
      this.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='" + this.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(this.param["width"] - this.param["leftArrWidth"]) + "px";
      rightarr.innerHTML = "<a onfocus='this.blur()' href='javascript:saarr[" + this.saindex + "].doStep(\"right\")'><img src='" + this.param["imagepath"] + "/scroll_right.gif' alt='' style='border:0;display:block' /></a>";
      this.horizTrack.appendChild(rightarr);

      targetdiv.appendChild(this.horizTrack);
    }

    if (this.param["vertScroller"]) {
      this.vertTrack = document.createElement("DIV");
      this.vertTrack.className = "sa_verttrack";
      this.vertTrack.style.position = "absolute";
      this.vertTrack.style.background = "url(" + this.param["imagepath"] + "/vert_track.gif)";
      this.vertTrack.style.display = "block";
      this.vertTrack.style.marginLeft = (this.param["vertScrollPosition"] == "left" ? "0" : String(this.param["width"] - this.param["vertTrackWidth"]) + "px");
      this.vertTrack.style.width = String(this.param["vertTrackWidth"]) + "px";
      this.vertTrack.style.height = String(this.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='" + this.param["imagepath"] + "/scroll_up.gif' alt='' style='border:0;display:block' /></a>";
      this.vertTrack.appendChild(uparr);

      var track = document.createElement("DIV");
      track.style.position = "absolute";
      track.style.marginTop = String(this.param["upArrHeight"]) + "px";
      var h = this.param["height"] - this.param["upArrHeight"] - this.param["downArrHeight"];
      track.style.height = String(h < 0 ? 0 : h) + "px";
      track.style.width = String(this.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'); };
      this.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='" + this.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(this.param["height"] - this.param["downArrHeight"]) + "px";
      downarr.innerHTML = "<a onfocus='this.blur()' href='javascript:saarr[" + this.saindex + "].doStep(\"down\")'><img src='" + this.param["imagepath"] + "/scroll_down.gif' style='border:0;display:block' /></a>";
      this.vertTrack.appendChild(downarr);

      targetdiv.appendChild(this.vertTrack);
    }
  };

  this.setupParams = function() {
    if (this.param == null) this.param = new Object();

    if (typeof(targetdiv) != "object")
      targetdiv = document.getElementById(targetdiv);

    if (!this.param["horizStartPos"]) this.param["horizStartPos"] = 0;
    if (!this.param["vertStartPos"]) this.param["vertStartPos"] = 0;
    if (!this.param["horizStepSize"]) this.param["horizStepSize"] = 90;
    if (!this.param["vertStepSize"]) this.param["vertStepSize"] = 90;
    if (!this.param["vertStepSpeed"]) this.param["vertStepSpeed"] = 30;
    if (!this.param["horizStepSpeed"]) this.param["horizStepSpeed"] = 30;
    if (!this.param["horizScrollPosition"]) this.param["horizScrollPosition"] = 'bottom';
    if (!this.param["vertScrollPosition"]) this.param["vertScrollPosition"] = 'right';
    if (!this.param["vertScrollSpeed"]) this.param["vertScrollSpeed"] = 2;
    if (!this.param["horizScrollSpeed"]) this.param["horizScrollSpeed"] = 2;
    if (this.param["vertScroller"] == null) this.param["vertScroller"] = true;
    if (this.param["horizScroller"] == null) this.param["horizScroller"] = false;
    if (this.param["autoHide"] == null) this.param["autoHide"] = true;
    if (!this.param["imagepath"]) this.param["imagepath"] = 'admin/scrollarea';

    if (this.param["width"] == null || this.param["width"].length == 0) {
      var w = parseInt(this.getCssParam(targetdiv, "width", true));
      this.param["width"] = (w == 0 ? 200 : w);
    }
    if (this.param["height"] == null || this.param["height"].length == 0) {
      var h = parseInt(this.getCssParam(targetdiv, "height", true));
      this.param["height"] = (h == 0 ? 200 : h);
    }

    if (this.param["vertScroller"]) loadingImages += 4;
    if (this.param["horizScroller"]) loadingImages += 4;
    var obj = this;
    if (this.param["vertScroller"]) {
      if (!this.param["upArrHeight"]) setImgParam(obj, this.param["imagepath"] + "/scroll_up.gif", "upArrHeight", "height");
      if (!this.param["downArrHeight"]) setImgParam(obj, this.param["imagepath"] + "/scroll_down.gif", "downArrHeight", "height");
      if (!this.param["vertThumbLength"]) setImgParam(obj, this.param["imagepath"] + "/vert_slider.gif", "vertThumbLength", "height");
      if (!this.param["vertTrackWidth"]) setImgParam(obj, this.param["imagepath"] + "/vert_track.gif", "vertTrackWidth", "width");
    }
    if (this.param["horizScroller"]) {
      if (!this.param["leftArrWidth"]) setImgParam(obj, this.param["imagepath"] + "/scroll_left.gif", "leftArrWidth", "width");
      if (!this.param["rightArrWidth"]) setImgParam(obj, this.param["imagepath"] + "/scroll_right.gif", "rightArrWidth", "width");
      if (!this.param["horizThumbLength"]) setImgParam(obj, this.param["imagepath"] + "/horiz_slider.gif", "horizThumbLength", "width");
      if (!this.param["horizTrackHeight"]) setImgParam(obj, this.param["imagepath"] + "/horiz_track.gif", "horizTrackHeight", "height");
    }

  };

  this.resize = function(size) {
    this.param["width"] = size.width;
    this.param["height"] = size.height;
    this.scroller.width = this.param["width"];
    this.scroller.height = this.param["height"];
    this.scroller.trackWidth = this.param["width"] - this.param["leftArrWidth"] - this.param["rightArrWidth"];
    this.scroller.trackHeight = this.param["height"] - this.param["upArrHeight"] - this.param["downArrHeight"];

    targetdiv.style.width = this.param["width"] + "px";
    targetdiv.style.height = this.param["height"] + "px";

    if (this.param["horizScroller"]) {
      this.horizTrack.style.marginTop = (this.param["horizScrollPosition"] == "top" ? "0" : String(this.param["height"] - this.param["horizTrackHeight"]) + "px");
      this.horizTrack.style.width = String(this.param["width"]) + "px";

      var w = this.param["width"] - this.param["leftArrWidth"] - this.param["rightArrWidth"];
      this.horizTrack.childNodes[1].style.width = String(w < 0 ? 0 : w) + "px";
      this.horizTrack.childNodes[2].style.marginLeft = String(this.param["width"] - this.param["leftArrWidth"]) + "px";
    }

    if (this.param["vertScroller"]) {
      this.vertTrack.style.marginLeft = (this.param["vertScrollPosition"] == "left" ? "0" : String(this.param["width"] - this.param["vertTrackWidth"]) + "px");
      this.vertTrack.style.height = String(this.param["height"]) + "px";

      var h = this.param["height"] - this.param["upArrHeight"] - this.param["downArrHeight"];
      this.vertTrack.childNodes[1].style.height = String(h < 0 ? 0 : h) + "px";
      this.vertTrack.childNodes[2].style.marginTop = String(this.param["height"] - this.param["downArrHeight"]) + "px";
    }
    this.initScrollers();
  }

  this.setupObjects = function() {
    this.scroller.width = this.param["width"];
    this.scroller.height = this.param["height"];
    this.scroller.trackWidth = this.param["width"] - this.param["leftArrWidth"] - this.param["rightArrWidth"];
    this.scroller.trackHeight = this.param["height"] - this.param["upArrHeight"] - this.param["downArrHeight"];
    this.scroller.arrWidth = this.param["leftArrWidth"];
    this.scroller.arrHeight = this.param["upArrHeight"];
    this.scroller.vertStepSize = this.param["vertStepSize"];
    this.scroller.horizStepSize = this.param["horizStepSize"];
    this.scroller.vertStepSpeed = this.param["vertStepSpeed"];
    this.scroller.horizStepSpeed = this.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 = this.param["vertThumbLength"];
    this.thumbObj.size_horiz = this.param["horizThumbLength"];
  };

  this.setup = function() {
    this.setupObjects();
    this.setupHtml();
    this.initScrollers();

    this.thumbObj.elStart = 0;
    if (this.param["vertStartPos"] != 0) {
      var vertpos = -parseInt(this.scroller.height*this.param["vertStartPos"]/100);
      this.jumpTo("vertical", vertpos);
      this.scrollInfo.pos = vertpos;
    }
    if (this.param["horizStartPos"] != 0) {
      var horizpos = -parseInt(this.scroller.width*this.param["horizStartPos"]/100);
      this.jumpTo("horizontal", horizpos);
      this.scrollInfo.pos = horizpos;
    }
    this.setupdone = true;
    if (this.param.onSetupDone) this.param.onSetupDone(this);
  };

  this.saindex = saarr.length;
  saarr.push(this);
};

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);
  }
};

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++)
    if (!saarr[i].manualsetup) saarr[i].setupParams();
};


if (window.attachEvent)
  window.attachEvent("onload", sa_init);
else
  window.addEventListener("load", sa_init, false);
