function scrollBar(obal, obsah, posuvnik, rootWebu) {
  var own = this;
  //objekty
  own.obal = obal;
  own.obsah = obsah;
  own.posuvnik = posuvnik;
  own.rootWebu = rootWebu;
  own.sipkaNahoru = null;
  own.sipkaDolu = null;
  own.vodiciLinka = null;
  own.slider = null;

  //parametry pro nastavení chování
  own.krok = 40; //px
  own.casAnimaceKroku = 10; //ms
  own.rychlostPosunuPomalu = 0.1; // px/ms - pro automatický posun
  own.rychlostPosunuStredne = 0.3; // px/ms - pro automatický posun
  own.rychlostPosunuRychle = 0.6; // px/ms - pro posun z vnějšku
  
  //privatni promenne
  own.minVyskaSlideru = 10; //px
  own.posunovatSlider = false;
  own.slider_mouseDown_y = 0; //px
  own.pomerPosunuObsahuKuSlideru = 0; //px
  own.maxYSlideru = 0; //px
  own.maxPosunObsahu = 0; //px
  
  own.htmlStruktura =
    '<a id="sipkaNahoru" title="Posunout nahoru">&nbsp;</a>'+
    '<div id="vodiciLinka">'+
      '<div id="slider">&nbsp;</div>'+
    '</div>'+
    '<a id="sipkaDolu" title="Posunout dolů">&nbsp;</a>';
  
  //vykresleni
  own.posuvnik.append(own.htmlStruktura);
  own.sipkaNahoru = own.posuvnik.find('#sipkaNahoru');
  own.sipkaDolu = own.posuvnik.find('#sipkaDolu');
  own.vodiciLinka = own.posuvnik.find('#vodiciLinka');
  own.slider = own.posuvnik.find('#slider');

//obsluha scrollovani
  if (own.obsah.height() > own.obal.height()) { //udalosti a jejich obsluhy nabindujeme jen pokud jsou potreba
    //srovnani delty posunu
    own.deltaPosunu = function(event) {
      var delta = 0;
      if (event.detail) // FF
        delta = -event.detail / 3; //radky
      else if (event.wheelDelta) // ostatni prohlizece
        delta = event.wheelDelta / 40; //stupne
      return delta;
    }
    //obsluha eventu "scroll"
    own.scroll = function(event) {
      event = awm_checkEvent(event);
      awm_stopBubbling(event);
      var delta = own.deltaPosunu(event);
      var y = -parseInt(own.obsah.css('top'));
      if (delta > 0) { //scrolovani nahoru
        if (y > 0) { //jeste nejsme na konci
          var posun = own.krok;
          var cas = own.casAnimaceKroku;
          if (y < posun) { //pokud presahneme konec
            cas = Math.round(cas * (y / posun));
            posun = y;
          }
          y = y - posun;
          own.obsah.animate({top: (-y)}, {duration: cas, easing: 'linear'});
          //animovani slideru
          ySlider = Math.round(y / own.pomerPosunuObsahuKuSlideru);
          own.slider.animate({top: ySlider}, {duration: cas, easing: 'linear'});
        }
      }
      else if (delta < 0) { //scrolovani dolu
        if (y < own.maxPosunObsahu) { //jeste nejsme na konci
          var posun = own.krok;
          var cas = own.casAnimaceKroku;
          if ((y + posun) > own.maxPosunObsahu) { //pokud presahneme konec
            cas = Math.round(cas * ((own.maxPosunObsahu - y) / posun));
            posun = own.maxPosunObsahu - y;
          }
          y = y + posun;
          own.obsah.animate({top: (-y)}, {duration: cas, easing: 'linear'});
          //animovani slideru
          if (y == own.maxPosunObsahu)
            ySlider = own.maxYSlideru;
          else
            ySlider = Math.round(y / own.pomerPosunuObsahuKuSlideru);
          own.slider.animate({top: ySlider}, {duration: cas, easing: 'linear'});
        }
      }
    }
  
    //bindovani eventu na dane objekty
    own.obal.bind('DOMMouseScroll', function(event) { own.scroll(event); }); //FF
    own.obal.bind('mousewheel', function(event) { own.scroll(event); }); //opera, safari, google, IE9
    own.obal.bind('onmousewheel', function(event) { own.scroll(event); }); //IE < 9
  
  //obsluha navigacnich sipek
    own.stopScroll = function() {
      own.obsah.stop();
      own.slider.stop();
    }
    //eventy pro sipku nahoru
    own.autoScrollUp = function(event, rychlost) {
      event = awm_checkEvent(event);
      awm_stopBubbling(event);
      var y = parseInt(own.slider.css('top'));
      cas = Math.round(y / rychlost);
      own.slider.animate({top: 0}, {duration: cas, easing: 'linear'});
      own.obsah.animate({top: 0}, {duration: cas, easing: 'linear'});
    }
    own.sipkaNahoru.bind('mouseenter', function(event) {
      own.autoScrollUp(event, own.rychlostPosunuPomalu);
    });
    own.sipkaNahoru.bind('mousedown', function(event) {
      own.stopScroll();
      own.autoScrollUp(event, own.rychlostPosunuStredne);
    });
    own.sipkaNahoru.bind('mouseup', function(event) {
      own.stopScroll();
      own.autoScrollUp(event, own.rychlostPosunuPomalu);
    });
    own.sipkaNahoru.bind('mouseleave', function(event) {
      own.stopScroll();
    });
  
    //eventy pro sipku dolu
    own.autoScrollDown = function(event, rychlost) {
      event = awm_checkEvent(event);
      awm_stopBubbling(event);
      var y = parseInt(own.slider.css('top'));
      cas = Math.round((own.maxYSlideru - y) / rychlost);
      own.slider.animate({top: own.maxYSlideru}, {duration: cas, easing: 'linear'});
      own.obsah.animate({top: -own.maxPosunObsahu}, {duration: cas, easing: 'linear'});
    }
    own.sipkaDolu.bind('mouseenter', function(event) {
      own.autoScrollDown(event, own.rychlostPosunuPomalu);
    });
    own.sipkaDolu.bind('mousedown', function(event) {
      own.stopScroll();
      own.autoScrollDown(event, own.rychlostPosunuStredne);
    });
    own.sipkaDolu.bind('mouseup', function(event) {
      own.stopScroll();
      own.autoScrollDown(event, own.rychlostPosunuPomalu);
    });
    own.sipkaDolu.bind('mouseleave', function(event) {
      own.stopScroll();
    });
    
    //bindovani udalosti
    own.slider.bind('mousedown', function(event) {
      event = awm_checkEvent(event);
      awm_stopBubbling(event);
      own.posunovatSlider = true;
      own.slider_mouseDown_y = event.pageY - parseInt(own.vodiciLinka.css('top')) - parseInt(own.slider.css('top'));
    });
    //bindovani na obal kvuli moznosti odjeti kurzoru ze slideru
    own.obal.bind('mousemove', function(event) {
      event = awm_checkEvent(event);
      awm_stopBubbling(event);
      if (own.posunovatSlider) {
        var minulaPozice = parseInt(own.slider.css('top'));
        var ySlider = event.pageY - parseInt(own.vodiciLinka.css('top')) - own.slider_mouseDown_y;
        if (ySlider < 0)
          ySlider = 0;
        if (ySlider > own.maxYSlideru)
          ySlider = own.maxYSlideru;
        own.slider.css('top', ySlider+'px');
        //posun obsahu
        var y = 0;
        if (ySlider >= own.maxYSlideru)
          y = own.maxPosunObsahu;
        else
          y = Math.round(ySlider * own.pomerPosunuObsahuKuSlideru);
        own.obsah.animate({top: (-y)}, {duration: 0, easing: 'linear'});
      }
    });
    //bindovani na obal kvuli moznosti odjeti kurzoru ze slideru
    own.obal.bind('mouseup', function(event) {
      event = awm_checkEvent(event);
      awm_stopBubbling(event);
      own.posunovatSlider = false;
      own.slider_mouseDown_y = 0;
    });
  }
  else
    own.posuvnik.addClass('neaktivni');

  //nastaveni velikosti slideru
  var vyska = Math.round((own.vodiciLinka.height() * own.obal.height()) / own.obsah.height());
  vyska = Math.max(own.minVyskaSlideru, vyska);
  vyska = Math.min(own.vodiciLinka.height(), vyska);
  own.slider.css('height', vyska+'px');
  //nastaveni pomeru pro prepocet posunu
  own.maxYSlideru = own.vodiciLinka.height() - own.slider.outerHeight();
  own.maxPosunObsahu = own.obsah.outerHeight() - own.obal.innerHeight();
  own.pomerPosunuObsahuKuSlideru = own.maxPosunObsahu / own.maxYSlideru;

  //nastaveni pozice z vnejsku objeku
  own.nastavPoziciObsahu = function(novaPozice) {
    var y = -parseInt(own.obsah.css('top'));
    if (novaPozice > own.maxPosunObsahu)
      novaPozice = own.maxPosunObsahu;
    if (novaPozice < 0)
      novaPozice = 0;
    var cas = Math.round(Math.abs(y - novaPozice) / own.rychlostPosunuRychle);
    y = novaPozice;
    own.obsah.animate({top: (-y)}, {duration: cas, easing: 'swing'});
    //animovani slideru
    if (y >= own.maxPosunObsahu)
      ySlider = own.maxYSlideru;
    else if (y <= 0)
      ySlider = 0;
    else
      ySlider = Math.round(y / own.pomerPosunuObsahuKuSlideru);
    own.slider.animate({top: ySlider}, {duration: cas, easing: 'swing'});
  }

  own.destructor = function() {
    own.obal.unbind('DOMMouseScroll');
    own.obal.unbind('mousewheel');
    own.obal.unbind('onmousewheel');
    own.sipkaNahoru.unbind('mouseenter');
    own.sipkaNahoru.unbind('mousedown');
    own.sipkaNahoru.unbind('mouseup');
    own.sipkaNahoru.unbind('mouseleave');
    own.sipkaDolu.unbind('mouseenter');
    own.sipkaDolu.unbind('mousedown');
    own.sipkaDolu.unbind('mouseup');
    own.sipkaDolu.unbind('mouseleave');
    own.slider.unbind('mousedown');
    own.obal.unbind('mousemove');
    own.obal.unbind('mouseup');
  }
}
