var ElasticEffect = new Class({
	overflow:		0,
	elasticTop:		false,
	elasticBottom:	true,
	
	initialize: function() {
		this._setupDiv();
		setInterval(function(){this.update()}.bind(this), 3);
		window.addEvent('mousewheel', this.mouseScroll.bind(this));
	},
	
	_setupDiv: function() {
		var wrap = $('warper');
		console.log(wrap);
		var hider = new Element('div');
		wrap.injectInside(hider);
		hider.injectInside(document.body);
		hider.style.overflow = 'hidden';
		wrap.style.position = 'relative';
		this.wrap = wrap;
	},
	
	mouseScroll: function(w){
		var scroll = w.wheel*4;
		
		if(scroll>0) {
			if(!this.elasticTop) return;
			
			if (this.overflow<0) {
				this.overflow += scroll;
				if(this.overflow > 0) this.overflow = 0;
				w.preventDefault();
				
			} else if(this._isAtTop()) {
				this.overflow += scroll;
			}
			
		} else {
			if(!this.elasticBottom) return;
			
			if(this.overflow>0) {
				this.overflow += scroll;
				if(this.overflow < 0) this.overflow = 0;
				w.preventDefault();
				
			} else if(this._isAtBottom()) {
				this.overflow += scroll;
			}
		}
	},
	
	update: function() {
		this.overflow -= this.overflow/7;
		if(Math.abs(this.overflow) < 1)	this.overflow = 0;
		this.wrap.style.top = this.overflow+'px';
	},
	
	_isAtTop: function() {
		return (!document.body.getScroll().y);
	},
	
	_isAtBottom: function() {
		return (document.body.getScroll().y>=window.scrollMaxY);
	}
});

window.onload = function(){
	new ElasticEffect();
}
