var sesHScroller = {
  name : 'sesHScroller',
  obj : false,
  slides: new Array(),
  curSlide: 0,
  newSlide: 1,
  slideClass: 'scrollerSlide',
  disp: 128,
  sliding: false,
  startedAt: false,
  delay: 8,
  engine: false,
  autoEngine: false,

  init: function(obj, showWidth, showHeight){
	var j = 0, className = '';
	try{
	  this.obj = obj;
	  this.obj.style.position = 'relative';
	  this.obj.style.overflow = 'hidden';
	  this.obj.style.width = showWidth + 'px';
	  this.obj.style.height = showHeight + 'px';
	  this.obj.style.zIndex = '1';
	  this.disp = showWidth;
	  this.slideClass = this.slideClass.toLowerCase()
	  //--
	  var allDivs = obj.getElementsByTagName('div');
	  for(i = 0; i < allDivs.length; i++){
		if(allDivs[i].className && allDivs[i].className != '' && allDivs[i].className != null && allDivs[i].className != 'undefined'){
		  if(this.slideClass == allDivs[i].className.toLowerCase()){ this.slides[j++] = allDivs[i];} 
		}
	  }
	  //##--
	  for(x in this.slides){
		this.slides[x].style.width = showWidth + 'px';
		this.slides[x].style.height = showHeight + 'px';
		this.slides[x].style.zIndex = '1';
		this.slides[x].style.position = 'absolute';
		this.slides[x].style.top = '0px';
		this.slides[x].style.left = this.disp + 'px';
	  }
	  if(this.slides[0]){  this.slides[0].style.left = '0px';}
	  this.autoEngine = window.setInterval(this.name+'.slide(true);', this.delay * 1000);
	}catch(e){ return this.onError(this.name+'.init: '+e.message);}
	return true;
  },

  onError : function(e){
	window.status = 'Error: '+e;
	return true;
  },

  slide : function(to_next){
	try{
      if(this.sliding) return false;
      window.clearInterval(this.autoEngine);
      if(to_next){
        this.newSlide = (this.curSlide + 1 == this.slides.length) ? 0 : this.curSlide + 1;
        this.moveDiv(this.slides[this.newSlide], this.disp, 0);
		if(this.newSlide >= this.slides.length){ return false;}
		this.slides[this.newSlide].style.left = this.disp+'px';
	    this.engine = window.setInterval(this.name+'.sliderObject(-1);', this.delay);
      }else{
        this.newSlide = (this.curSlide  == 0) ? this.slides.length - 1 : this.curSlide - 1;
        this.moveDiv(this.slides[this.newSlide], this.disp * -1, 0);
		if(this.newSlide < 0){ return false;}
		this.slides[this.newSlide].style.left = '-'+this.disp+'px';
	    this.engine = window.setInterval(this.name+'.sliderObject(1);', this.delay);
      }

	}catch(e){ return this.onError(this.name+'.slide: '+e.message);}
	return true;
  },
  
  sliderObject : function(mode){
    try{
      this.sliding = true;
      var factor = 3;
      var newX = parseInt(this.slides[this.newSlide].style.left) + (factor * mode);
      this.moveDiv(this.slides[this.curSlide], parseInt(this.slides[this.curSlide].style.left) + (factor * mode), 0);
      this.moveDiv(this.slides[this.newSlide], newX, 0);
      if(mode == -1 && newX <= 0){
        window.clearInterval(this.engine);
        this.autoEngine = window.setInterval(this.name+'.slide(true);', this.delay * 1000);
        this.moveDiv(this.slides[this.newSlide], 0, 0);
        this.curSlide = this.newSlide;
        this.sliding = false;
        return true;
      }else if(mode == 1 && newX >= 0){
        window.clearInterval(this.engine);
        this.autoEngine = window.setInterval(this.name+'.slide(true);', this.delay * 1000);
        this.moveDiv(this.slides[this.newSlide], 0, 0);
        this.curSlide = this.newSlide;
        this.sliding = false;
        return true;
      }
    }catch(e){ return this.onError(this.name+'.sliderObject: '+e.message);}
	return true;
  },
  
  moveDiv : function(obj, x, y){
	try{
	  obj.style.left = parseInt(x)+ 'px';
	  obj.style.top = parseInt(y)+ 'px';
	}catch(e){ return this.onError(this.name+'.moveDiv: '+e.message);}
	return true;
  }
};
 