function scroller(id, objInstance)
{
  this.id = id;
  this.counterId = "scrollerCounter_"+this.id;
  this.elements = new Array();
  this.elementClass = "scrollerContent";
  this.elementSeparator = "_cont_";
  this.currentElement = 0;
  this.obj = objInstance;
  
  this.showAllItems = false;
  
  this.appFolder = "js/scroller/";
  this.scrollerNextId = "next_"+this.id;
  this.scrollerNextImgSrc = this.appFolder+"scrollerNext.gif";
  this.scrollerPrevId = "prev_"+this.id;
  this.scrollerPrevImgSrc = this.appFolder+"scrollerPrev.gif";
  this.scrollerUpDownId = "ud_"+this.id;
  this.scrollerUpDownImgSrc = this.appFolder+"scrollerUpDown.gif";
  this.scrollerDownUpImgSrc = this.appFolder+"scrollerDownUp.gif";

  this.$ = function (id)
  {
    return document.getElementById(id);
  }

  this.getChildren = function ()
  {

    divs = this.$(this.id).getElementsByTagName("div");
    j=0;
    for(i in divs)
    {
      if(divs[i].parentNode && divs[i].parentNode.id==this.id)
      {
        divs[i].id = this.id+this.elementSeparator+i;
        this.elements[j++] = divs[i];
        //divs[i].className = this.elementClass;
      }
    }
    return this.elements;
  }
  
  this.setObj = function (obj)
  {
    this.obj = obj;
    alert(this.obj.id);
  }
  
  this.insertButtons = function ()
  {
    if(this.elements.length>1)
    {
      var bPrev = document.createElement('img');
      //bPrev.type="image"
      bPrev.id = this.scrollerPrevId;
      bPrev.src = this.scrollerPrevImgSrc;
      bPrev.alt = "<<";
      bPrev.className = "scrollerImage";
      bPrev.style.cursor="pointer";
      var code0 = this.obj+'.show(-1)';
      bPrev.onclick = function () 
      {
          eval(code0);
      }; 
      
      var bNext = document.createElement('img');
      //bNext.type="image"
      bNext.id = this.scrollerNextId;
      bNext.src = this.scrollerNextImgSrc;
      bNext.alt = ">>";
      bNext.className = "scrollerImage";
      bNext.style.cursor="pointer";
      
      var code1 = this.obj+'.show(1)';
      
      bNext.onclick = function () 
      {
          eval(code1);
      }; 
      
      var bUD = document.createElement('img');
      //bUD.type="image"
      bUD.id = this.scrollerUpDownId;
      bUD.src = this.scrollerUpDownImgSrc;
      bUD.className = "scrollerImage";
      bUD.alt = " ";
      bUD.style.cursor="pointer";
      
      var code2 = this.obj+'.showAll()';
      
      bUD.onclick = function () 
      {
          eval(code2);
      }; 
  
      var countDiv = document.createElement('p');
      countDiv.id = this.counterId;
      countDiv.innerHTML = '<b>' + (this.currentElement+1) + '</b> / ' + this.elements.length;
      countDiv.className = "scrollerCounter";
      
      mainDiv = this.$(this.id);
      mainDiv.insertBefore(countDiv, mainDiv.firstChild);
      mainDiv.insertBefore(bNext, mainDiv.firstChild);
      mainDiv.insertBefore(bUD, mainDiv.firstChild);
      mainDiv.insertBefore(bPrev, mainDiv.firstChild);
    }
  }
  
  this.setCurrentElementNum = function ()
  {
    this.$(this.counterId).innerHTML = '<b>' + (this.currentElement+1) + '</b> / ' + this.elements.length;
  }
  
  this.showAll = function()
  {
    ud = this.$(this.scrollerUpDownId);
    
    if(this.showAllItems)
    {
      ud.src = this.scrollerUpDownImgSrc;
      this.show(0);
      this.showAllItems = false;
    }
    else
    {
      ud.src = this.scrollerDownUpImgSrc;
      
      for(i=0; i< this.elements.length ; i++ )
      {
        this.elements[i].style.display = "block";
      }
      this.showAllItems = true;
    }
  }
  
  this.show = function (nextPrev)
  {
    c = this.currentElement;
    i = this.elements.length-1;
  
    if(!(c>=i && nextPrev>0 || nextPrev<0 && c<=0))
    {
      this.currentElement += nextPrev;
      if(i>1)this.$(this.scrollerUpDownId).src = this.scrollerUpDownImgSrc;
    }
    
    if(i>0)this.setCurrentElementNum();
    
    for(i=0; i< this.elements.length ; i++ )
    {
      this.elements[i].style.display = "none";
    }
      
    this.elements[this.currentElement].style.display = "block";
    this.showAllItems = false;
  }
  
  this.run = function ()
  {
    this.getChildren();
    this.insertButtons();
    this.show(0);
  }

  /**uruchamiamy przy tworzeniu obiektu*/
  this.run();
  //this.insertActionToBody();
  
}
/**
@example
var ab = new scroller("scroller", "ab");
var ab1 = new scroller("scroller2", "ab1");
*/
