/* --------------------------------------------------------------- 
   Author : Remi Palard
   June 2008
   remi.palard@gmail.com  
--------------------------------------------------------------- */

$(document).observe("dom:loaded", function() {
  
  // Custom Selectbox for search
  var selectbox = new Autocompleter.SelectBox('webdoc-quicksearch-type',{
    keepSelectWidth:false,
    autocompleteClassName: 'webdoc-quicksearch-select',
    afterUpdateElement: function() { quickSearch._focus(); },
    customizeResult: function(v) { return v.substring(0,7); }
  }); 
  
  // Search Box
  quickSearch.init();

});

/* --------------------------------------------------------------- */

Control.Scroller = Class.create();
Control.Scroller.prototype = {
  initialize: function(container, handle, track) {
    this.container = $(container);    
    this.handle = $(handle);
    this.track = $(track);          
    
    this.slider = new Control.Slider(this.handle, this.track, {
      'axis' : 'vertical',
      onSlide: function(v) { this.scrollVertical(v); }.bind(this),
      onChange: function(v) { this.scrollVertical(v); }.bind(this)
    });     
      
    // Hide if not usefull
    this.autoHide();          
  },
  
   /* ----------------------------------- */ 

   // Scroll the element vertically based on its width and the slider maximum value
  scrollVertical: function(value) {
   this.currentValue = value;
   this.container.scrollTop = Math.round(value/this.slider.maximum*(this.container.scrollHeight-this.container.offsetHeight));
  },
  
   /* ----------------------------------- */ 
  
  // Disable vertical scrolling if text doesn't overflow the div
  autoHide: function() {
    if (this.container.scrollHeight <= this.container.offsetHeight) {
      this.slider.setDisabled();
      this.track.hide();
    }
  }
};