/* ## Hans Reuffurth GmbH - Unternehmen für digitale Kommunikation ## */
var ScrollBar = new Class({
  options: {
    maxThumbSize: 15,
    wheel: 8,
    arrows: true,
    hScroll: true
  },
  initialize: function(main, content, options){
    this.setOptions(options);
    this.main = $(main);
    this.content = $(content);
    if (this.options.arrows == true){
      this.arrowOffset = 30;
    } else {
      this.arrowOffset = 0;
    }
    if (this.options.hScroll == true){
      this.hScrollOffset = 15;
    } else {
      this.hScrollOffset = 0;
    }
    this.vScrollbar = new Element('div', {
      'class': 'vScrollbar'
    }).injectAfter(this.content);
    if (this.options.arrows == true){
      this.arrowUp = new Element('div', {
        'class': 'arrowUp'
      }).injectInside(this.vScrollbar);
    }
    this.vTrack = new Element('div', {
      'class': 'vTrack'
    }).injectInside(this.vScrollbar);
    this.vThumb = new Element('div', {
      'class': 'vThumb'
    }).injectInside(this.vTrack);
    if (this.options.arrows == true){
      this.arrowDown = new Element('div', {
        'class': 'arrowDown'
      }).injectInside(this.vScrollbar);
    }
    this.hScrollbar = new Element('div', {
      'class': 'hScrollbar'
    }).injectAfter(this.vScrollbar);
    if (this.options.arrows == true){
      this.arrowLeft = new Element('div', {
        'class': 'arrowLeft'
      }).injectInside(this.hScrollbar);
    }
    this.hTrack = new Element('div', {
      'class': 'hTrack'
    }).injectInside(this.hScrollbar);
    this.hThumb = new Element('div', {
      'class': 'hThumb'
    }).injectInside(this.hTrack);
    if (this.options.arrows == true){
      this.arrowRight = new Element('div', {
        'class': 'arrowRight'
      }).injectInside(this.hScrollbar);
    }
    this.corner = new Element('div', {
      'class': 'corner'
    }).injectAfter(this.hScrollbar);
    this.bound = {};
    this.vPosition = {};
    this.hPosition = {};
    this.vMouse = {};
    this.hMouse = {};
    this.update();
    this.addSpacer();
  },
  addSpacer: function(){
  },
  update: function(){
    this.main.setStyle('height', this.content.offsetHeight + 10 + this.hScrollOffset);
    this.vTrack.setStyle('height', this.content.offsetHeight + 10 - this.arrowOffset);
    this.main.setStyle('width', this.content.offsetWidth + 10 + 15);
    this.hTrack.setStyle('width', this.content.offsetWidth + 10 - this.arrowOffset);
    this.vScrollbar.setStyle('display', 'block'); // Remove and replace vertical scrollbar
    if (this.options.hScroll == true){
      this.hScrollbar.setStyle('display', 'block'); // Remove and replace horizontal scrollbar
      this.corner.setStyle('display', 'block'); // Remove and replace bottom right corner spacer
      // Horizontal
      this.hContentSize = this.content.offsetWidth + 10;
      this.hContentScrollSize = this.content.scrollWidth;
      this.hTrackSize = this.hTrack.offsetWidth;
      this.hContentRatio = this.hContentSize / this.hContentScrollSize;
      this.hThumbSize = (this.hTrackSize * this.hContentRatio).limit(this.options.maxThumbSize, this.hTrackSize);
      this.hScrollRatio = this.hContentScrollSize / this.hTrackSize;
      this.hThumb.setStyle('width', this.hThumbSize);
    } else {
      this.hScrollbar.setStyle('display', 'none');
      this.corner.setStyle('display', 'none');
    }
    // Vertical
    this.vContentSize = this.content.offsetHeight + 10 - 14;
    this.vContentScrollSize = this.content.scrollHeight;
    this.vTrackSize = this.vTrack.offsetHeight;
    this.vContentRatio = this.vContentSize / this.vContentScrollSize;
    this.vThumbSize = (this.vTrackSize * this.vContentRatio).limit(this.options.maxThumbSize, this.vTrackSize);
    this.vScrollRatio = this.vContentScrollSize / this.vTrackSize;
    this.vThumb.setStyle('height', this.vThumbSize);
  }
});
ScrollBar.implement(new Events, new Options);

/* ##################################################### voxmedien ## */
