document.observe('dom:loaded', function(){
  files = new NVB.files({
    onload:init,
    scripts: new Array(
      'supersleight.js',
      'effects.js'
    )
    //,google_analytics: "UA-4059529-1"
  })
});
function init(){
 new NVB.scroll();
}
if (Object.isUndefined(NVB)) { var NVB = { } }
NVB.scroll = Class.create({
	initialize: function() {
		this.inner = $('inner')
		this.content = $('content')
		this.balk = $('balk')
		this.offset = -16;
		this.count = 0;
		
		this.events = {
			click: this.click.bind(this)
		};

		this.total_height = this.content.getHeight() + parseFloat(this.content.getStyle('padding-top').gsub('px', '')) + parseFloat(this.content.getStyle('padding-bottom')) + this.offset;
		this.total_inner_height = this.inner.getHeight() + parseFloat(this.inner.getStyle('padding-top').gsub('px', '')) + parseFloat(this.inner.getStyle('padding-bottom'));
		
		
		if(this.content && this.balk){
			this.buttons = new Array(
				this.balk.select('a.scroll_up').first(),
				this.balk.select('a.scroll_down').first()
			).invoke('hide');
			
			this.overFlow = this.total_height - this.total_inner_height - 20;
			
			this.maxCount = Math.ceil( this.total_height / ( this.total_inner_height - 20 ) ) ;
			
			if( this.overFlow > 0 ){
				this.buttons.last().show();
				
				this.buttons.each(function(s){
					s.onclick = this.click.bind(this,s);
				}, this);
			}
		}
	},
	click:  function( elm, e ){
		var delta = elm.hasClassName('scroll_up') ? -1 : 1;

			this.count += delta;
			
			if( this.count < 0 ) this.count = 0;
			if( this.count > this.maxCount) this.count--;
			
			this.move();
	},
	move: function(){
		if(this.animating){
			this.animating.cancel();
			this.animating = null;
		}
		
		this.animating = new Effect.Move(this.content, { x: 220 , y: -this.count * ( this.total_inner_height - 20 ) ,  mode: 'absolute'});
		
		if(this.count == 0)this.buttons.first().hide();
		else this.buttons.first().show();

		if( this.count == this.maxCount-1) this.buttons.last().hide();
		else this.buttons.last().show();
		
		return false;
	}
});
