
  nutShell.blockslide = {};  

  /* 
   *
   *  ---- Module -----
   *
   */


  nutShell.blockslide = function(options){
    this.Version = '0.1.2';
    
    this.vertical = options.vertical ? options.vertical : false;

    this.containerEL = $(options.containerEL);
    this.sliderEL = $(options.sliderEL);
    this.prevEL = $(options.prevEL);
    this.nextEL = $(options.nextEL);
    this.thumbEL = $(options.thumbEL);
    
    this.slidePanelClass = options.slidePanelClass ? options.slidePanelClass : 'slidePanel';
    this.jumpToClass = options.jumpToClass ? options.jumpToClass : 'jumpTo';
    this.jumpToHoverClass = options.jumpToHoverClass ? options.jumpToHoverClass : 'jumpToHover';
    
    this.loop = options.loop ? options.loop : false;
    this.autoStart = options.autoStart ? options.autoStart : false;
    
    this.slideDelay = options.slideDelay ? options.slideDelay : 3000;
    this.mode = options.mode ? options.mode : 3000;
    
    this.playStatus = 'init';
    this.playReverse = options.playReverse ? options.playReverse : false;
   
    this.slideWidth = options.slideWidth;
    this.slideHeight = options.slideHeight;
    this.slideCount = $$('#'+ this.containerEL.identify() +' .' + this.slidePanelClass).size();    
    this.currentSlide = options.currentSlide != null ? options.currentSlide : 0;
    
    this.timer = 0;
    this.play = function(){
      clearTimeout(this.timer);
      var _self = this;
      this.timer = setTimeout(function(ms){
        _self.doNextSlide();
        setTimeout(function(ms){
          _self.play();
        }, _self.slideDelay);
      }, _self.slideDelay);
      this.playStatus = 'playing';
    }
    this.stop = function(){
      clearTimeout(this.timer);
      this.playStatus = 'stopped';
    }

    
    this.colorThumb = function(){
      if(this.thumbEL){
        var _self = this;
        $$('#'+ this.thumbEL.identify() +' .'+this.jumpToClass).each(function(e){e.removeClassName(_self.jumpToHoverClass);});
        $$('#'+ this.thumbEL.identify() +' .'+this.jumpToHoverClass+'_'+this.currentSlide).each(function(e){e.addClassName(_self.jumpToHoverClass);});
        
      }
    }
    
    this.doNextSlide = function(){
      if (!this.playReverse){
        this.slideNext();
      }else{
        this.slidePrev();
      }

      this.moveSlide(this.currentSlide, false);
      return false;
    }
    this.slidePrev = function(){
      this.currentSlide--;
      if (this.currentSlide < 0){
        if(this.loop){
          this.currentSlide = this.slideCount-1;
        }else{
          this.stop();
          this.currentSlide = 0;
        }
      }
      this.moveSlide(this.currentSlide, false);
      return false;
    }
    this.slideNext = function(){
      this.currentSlide++;
      if (this.currentSlide > this.slideCount-1){
        if(this.loop){
          this.currentSlide = 0;
        }else{
          this.stop();
          this.currentSlide = this.slideCount-1;
        }
      }

      this.moveSlide(this.currentSlide, false);
      return false;
    }

    
    if(this.thumbEL){
      var tIter = 0;
      var _self = this;
      
      $$('#'+ this.thumbEL.identify() +' .'+this.jumpToClass).each(function(e){
        var id=tIter; 
        Event.observe(e, 'click', function(ee) {_self.moveSlide(id);});
        e.addClassName(_self.jumpToHoverClass+'_'+id);
        tIter++;
      });
      if (!tIter && nutShell.debug)
        alert('Couldn\'t find any thumbnails marked with class '+this.jumpToClass+' in #'+this.thumbEL.identify());
    }

    if(this.prevEL)
      Event.observe(this.prevEL, 'click', this.slidePrev.bind(this));
    if(this.nextEL)
      Event.observe(this.nextEL, 'click', this.slideNext.bind(this));

    if (options.prevEL != undefined && !$(options.prevEL) && nutShell.debug)
      alert('Couldn\'t find prev button #'+options.prevEL);
    if (options.nextEL != undefined && !$(options.nextEL) && nutShell.debug)
      alert('Couldn\'t find next button #'+options.nextEL);


    /* 
     *
     *  ---- TRANSITIONS -----
     *
     */
     
    this.transitions = {};  
    this.transitions.switchContents = function(slide){
      jumpTo = true;
      if (!this.vertical){
        if (jumpTo){
          this.sliderEL.style.left = -(this.slideWidth * slide) + 'px';
        }else{
          new Effect.Move(this.sliderEL, { x: -(this.slideWidth * slide), y: 0, mode: 'absolute' });
        }
      }else{
        if (jumpTo){
          this.sliderEL.style.top = -(this.slideHeight * slide) + 'px';
        }else{
          new Effect.Move(this.sliderEL, { x: 0, y: -(this.slideHeight * slide), mode: 'absolute' });
        }
      }
      this.currentSlide = slide;
      this.colorThumb();
      if (this.playStatus == 'playing')
        this.play();
    }
    this.transitions.slideContents = function(slide, jumpTo){
      if (!this.vertical){
        if (jumpTo){
          this.sliderEL.style.left = -(this.slideWidth * slide) + 'px';
        }else{
          new Effect.Move(this.sliderEL, { x: -(this.slideWidth * slide), y: 0, mode: 'absolute' });
        }
      }else{
        if (jumpTo){
          this.sliderEL.style.top = -(this.slideHeight * slide) + 'px';
        }else{
          new Effect.Move(this.sliderEL, { x: 0, y: -(this.slideHeight * slide), mode: 'absolute' });
        }
      }
      this.currentSlide = slide;
      this.colorThumb();
      if (this.playStatus == 'playing')
        this.play();
    }
    this.transitions.initStack = function(){
      var _self = this;
      var tIter = 0;
      $$('#'+ this.sliderEL.identify() +' .slidePanel').each(function(e){
        e.style.position = 'absolute';
        if (_self.currentSlide < tIter){
          e.style.left = _self.slideWidth + 'px';
        }else{
          e.style.left = 0;
        }
        //new Effect.Move(e { x: this.slideWidth, y: 0, mode: 'absolute' });
        tIter++;
      
      });
      
    }
    this.transitions.stackContents = function(slide, jumpTo){
      //return false;
      var tTop = 0;
      var tLeft = 0;
      var panels = $$('#'+ this.sliderEL.identify() +' .slidePanel');
      if (!this.vertical){
        
      }else{
        tTop = 0;
      }
      if (jumpTo){
        panels[slide].style.left = tLeft + 'px';
        panels[slide].style.top = tTop + 'px';
      }else{
        new Effect.Move(panels[slide], { x: tLeft, y: tTop, mode: 'absolute' });
      }

      var _self = this;
      var tIter=0;
      panels.each(function(e){
        if ((tIter > slide)){
          if (!this.vertical){
            tLeft = _self.slideWidth;
          }else{
            tTop = _self.slideHeight;
          }
        }else if((tIter <= slide)){
          tLeft = 0;
          tTop = 0;
        }
        new Effect.Move(e, { x: tLeft, y: tTop, mode: 'absolute' });      
        tIter++;
      });
      this.currentSlide = slide;
      this.colorThumb();
      if (this.playStatus == 'playing')
        this.play();
    }


    /* 
     *
     *  ---- ALMOST LOADED! -----
     *
     */
    
    this.initSlide = function(){};
    
    if (this.mode == 'stack'){
      this.initSlides = this.transitions.initStack;
      this.moveSlide = this.transitions.stackContents;
    }else if(this.mode == 'switch'){
      this.moveSlide = this.transitions.switchContents;
    }else{
      this.moveSlide = this.transitions.slideContents;
    }

    if (this.initSlides)
      this.initSlides();
    this.moveSlide(this.currentSlide, true);

    this.playStatus = 'ready';
    if(this.autoStart)
      this.play();
  }