var ScrollbarIpad = new Class({
  initialize: function(cont) {
    this.scrollable = cont;
    this.init();
    
    window.onresize = this.window_resize.bind(this);
    
  },
  
  init:function() {
    // Conteneur du scrollable
    this.scrollable.setStyles({
      'overflow-x': 'hidden',
	  'overflow-y': 'auto'
    });
	this.wrap = new Element('div', {'class': 'scrollable'}).wraps(this.scrollable);
	this.scrollable.set('class', 'scrollable_wrap');
	this.wrap = this.scrollable;
	this.scrollable = this.wrap.getParent();
	this.haut = new Element('div', {
		'class': 'scrollipad haut'
	}).inject(this.scrollable.getParent());
	this.bas = new Element('div', {
		'class': 'scrollipad bas'
	}).inject(this.scrollable.getParent());
	
	this.haut.addEvents({
		'mousedown': this.downHaut.bind(this),
		'mouseup': this.upHaut.bind(this)
	});
	
	this.bas.addEvents({
		'mousedown': this.downBas.bind(this),
		'mouseup': this.upBas.bind(this)
	});
	
	this.scrollable.addEvent('scroll', function(){});
	
	var speed = this.wrap.getScroll().y * 500;
	
	this.wrap = new Movable(this.wrap);
	this.wrap.property = 'top';
	this.wrap.src = 0;
	this.wrap.dest = - this.wrap.cont.getSize().y + this.scrollable.getSize().y;
	this.wrap.fx = new Fx.Tween(this.wrap.cont, {link:'cancel', duration: 500});
	
	/*
    this.scrollable_cont.inject(this.scrollable.getParent());
    this.scrollable.inject(this.scrollable_cont);
    // On cache la scrollbar d'origine
    this.scrollable.setStyles({
      'width': '105%',
      'top': 0,
      'bottom': 0
    });
    // Scrollbar handler
    // Background
    this.scroll_handler_bkg = new Element('div', {
      'class': 'scroll_handler_bkg'
    });
    this.scroll_handler = new Element('div', {
      'class': 'scroll_handler',
      'styles': {
        'top': 0
      }
    });
	new Element('img', {
		'src': '/images/scroll_haut.gif',
		'class': 'scroll_haut'
	}).inject(this.scroll_handler);
	new Element('img', {
		'src': '/images/scroll_bas.gif',
		'class': 'scroll_bas'
	}).inject(this.scroll_handler);
    this.init_scroll_handler();
    this.scroll_handler.inject(this.scroll_handler_bkg.inject(this.scrollable_cont));
    
    this.scrollable.addEvent('click', function(e){
      //e.stop();
      //console.log('click');
    });
	*/
  },
  
  downHaut:function() {
	  this.wrap.close();
  },
  
  upHaut:function() {
	  this.wrap.fx.cancel();
  },
  
  downBas:function() {
	  this.wrap.open();
  },
  
  upBas:function() {
	  this.wrap.fx.cancel();
  },
  
  window_resize: function() {
    //this.init_scroll_handler();
  }
  
});
