function ustawRoller(id,index){
var scrollLeft = 0;
var roller = document.getElementById(id);
var rollerC = roller.firstChild.nextSibling.nextSibling;
//var colW = rollerC.firstChild.rows[0].cells[0].offsetWidth;

colW = 117;

var scrollLeft = index * (colW);

rollerC.scrollLeft = scrollLeft;
}



function rollerGallery(id,cols,index,way,direction)
    {
      this.roller = document.getElementById(id);
      this.rollerL = this.roller.firstChild; 
      this.rollerC = this.roller.firstChild.nextSibling.nextSibling;
      this.rollerR = this.rollerC.nextSibling.nextSibling;
      this.cols = parseInt(cols);
      
      this.colW = this.rollerC.firstChild.rows[0].cells[0].offsetWidth;
      this.colH = this.rollerC.firstChild.rows[0].cells[0].offsetHeight;
      
      this.index = parseInt(index);
      this.curPos = 0;
      this.endPos = 0;
      this.stepPos = 0;
      
      this.direction = 1;
          
      this.stepVertical = function()
      {
        if (this.owner) this.owner = this.owner;
        else this.owner = this;
         
        var diff = Math.abs(this.owner.endPos - this.owner.curPos);
        
        if (diff < 10)
        {
          this.owner.curPos += this.owner.direction * diff;
          this.owner.rollerC.scrollLeft = this.owner.curPos;
          
          return false;
        }
        
        var stepPie = Math.round(diff / 5);
        
        
        if (stepPie < 10) stepPie = 10;
        
        this.owner.curPos += this.owner.direction * stepPie; 
        
        this.owner.rollerC.scrollLeft = this.owner.curPos; 
        
        if (!window.owner) window.owner = this;
        
        setTimeout(this.owner.stepVertical,100);        
      }
      this.stepHorizontal = function()
      {
        if (this.owner) this.owner = this.owner;
        else this.owner = this;
         
        var diff = Math.abs(this.owner.endPos - this.owner.curPos);
        
        if (diff < 10)
        {
          this.owner.curPos += this.owner.direction * diff;
          this.owner.rollerC.scrollTop = this.owner.curPos;
          
          return false;
        }
        
        var stepPie = Math.round(diff / 5);
        
        
        if (stepPie < 10) stepPie = 10;
        
        this.owner.curPos += this.owner.direction * stepPie; 
        
        this.owner.rollerC.scrollTop = this.owner.curPos; 
        
        if (!window.owner) window.owner = this;
        
        setTimeout(this.owner.stepHorizontal,100);        
      }
      this.top = function()
      {
       
       if (this.owner) this.owner = this.owner;
        else this.owner = this;
        
        
        this.owner.curPos = this.owner.rollerC.scrollTop;
        this.owner.stepPos = this.owner.curPos;
        this.owner.direction = -1;
      
        this.owner.index -= this.owner.cols;
        if (this.owner.index < 0) this.owner.index = 0;
        
        var scrollTop = this.owner.index * this.owner.colH;
        
        this.owner.endPos = scrollTop;
        
        
        this.owner.rollerR.style.visibility = 'visible';
        
        if (this.owner.index == 0)
        {
           this.owner.rollerL.style.visibility = 'hidden';
        }
        
        this.owner.stepHorizontal();
       
      }
      this.bottom = function()
      {
       
       if (this.owner) this.owner = this.owner;
        else this.owner = this;
                                
        this.owner.curPos = this.owner.rollerC.scrollTop;
        this.owner.stepPos = this.owner.curPos;
        this.owner.direction = 1;
        
        var lastIndex = this.owner.index;
                      
        if (this.owner.rollerC.scrollHeight - this.owner.rollerC.scrollTop > this.owner.cols * this.owner.colH) this.owner.index += this.owner.cols;
        
        var scrollTop = this.owner.index * this.owner.colH;
        
        this.owner.endPos = scrollTop;
        
        this.owner.rollerL.style.visibility = 'visible';
        
        if (lastIndex + this.owner.cols == this.owner.index || this.owner.rollerC.scrollHeight - scrollTop < this.owner.cols * this.owner.colH)
        {
           this.owner.rollerR.style.visibility = 'hidden';
        }
        
        this.owner.stepHorizontal();
       
      }
      this.left = function()
      {
        if (this.owner) this.owner = this.owner;
        else this.owner = this;
       
        this.owner.curPos = this.owner.rollerC.scrollLeft;
        this.owner.stepPos = this.owner.curPos;
        this.owner.direction = -1;
      
        this.owner.index -= this.owner.cols;
        if (this.owner.index < 0) this.owner.index = 0;
        
        var scrollLeft = this.owner.index * this.owner.colW;
        
        this.owner.endPos = scrollLeft;
        
        
        this.owner.rollerR.style.visibility = 'visible';
        
        if (this.owner.index == 0)
        {
           this.owner.rollerL.style.visibility = 'hidden';
        }
        
        this.owner.stepVertical();
      }
      this.right = function()
      {
        if (this.owner) this.owner = this.owner;
        else this.owner = this;
                                
        this.owner.curPos = this.owner.rollerC.scrollLeft;
        this.owner.stepPos = this.owner.curPos;
        this.owner.direction = 1;
        
        
        
        var lastIndex = this.owner.index;
                      
        if (this.owner.rollerC.scrollWidth - this.owner.rollerC.scrollLeft > this.owner.cols * this.owner.colW) this.owner.index += this.owner.cols;
        
        var scrollLeft = this.owner.index * this.owner.colW;
        
       
        
        this.owner.endPos = scrollLeft;
        
        this.owner.rollerL.style.visibility = 'visible';
       
        if (this.owner.rollerC.scrollWidth - scrollLeft < this.owner.cols * this.owner.colW)
        {
           this.owner.rollerR.style.visibility = 'hidden';
        }
        
        this.owner.stepVertical();
      }
      
     
      
      //this.rollerC.scrollLeft = 0;
      this.rollerL.owner = this;
      
      if (!direction)
        this.rollerL.onclick = this.left;
      else  
        this.rollerL.onclick = this.top;
        
      this.rollerR.owner = this;
      if (!direction) 
       this.rollerR.onclick = this.right;
      else
       this.rollerR.onclick = this.bottom;
       
      if (!direction) {
      if(way == 1) this.right();
      else this.left();
      }
      else
      {
       this.bottom();
      }
    }

