Effect.HoverVerticalScroll = Class.create();
Object.extend(Object.extend(Effect.HoverVerticalScroll.prototype, Effect.Base.prototype), 
{
	initialize: function(aperature_uid) {
		this.aperature = $(aperature_uid);
		if(this.aperature) {
			this.active = false;
			this.seconds_per_page_scrolled = 1.5;
			this.transition = Effect.Transitions.sinoidal;
			this.aperature.style.cursor = 'auto';
			this.h = Element.getHeight(this.aperature);
			this.sh = this.aperature.scrollHeight;
			this.duration = this.seconds_per_page_scrolled*(this.sh/this.h);
			
			this.py = 0;
			this.ny = 0;
			this.fy = 0;
			this.ty = 0;
			this.nsy = 0;
			
			this.eventMouseMove = this.scroll.bindAsEventListener(this);
			Event.observe(this.aperature, 'mousemove', this.eventMouseMove);
			this.eventMouseOut = this.endScroll.bindAsEventListener(this);
			Event.observe(this.aperature, 'mouseout', this.eventMouseOut);
		}
	},
	destroy: function() {
		Event.stopObserving(document, 'mousemove', this.eventMouseMove);
		Event.stopObserving(document, 'mouseout', this.eventMouseOut);
	},
	update: function(position) 
	{
		this.aperature.scrollTop = position;
		this.ny = position/this.h;
	},
	scroll: function(event) {
		//if we are in the top 1/3 of the client area, then scroll up if possible!
		this.py = Event.pointerY(event);
		this.ny = this.py/this.h;
		this.fy = this.aperature.scrollTop;
		this.ty = this.sh - this.h;
		
		if(this.ny <= 1.0/3.0) {
			if(!this.active) {
				this.nsy = this.fy/this.ty;
				var duration = (this.nsy)*this.duration;
				var options = Object.extend({
					from: this.aperature.scrollTop,
					to:   0,
					duration: duration,
					transition: this.transition
				}, {});
				this.start(options);
				this.active = true;
				this.aperature.style.cursor = 'pointer';
			}
		}
		else if(1.0/3.0 < this.ny && this.ny < 2.0/3.0) {	
			this.stopScroll();
		}
		else if(2.0/3.0 < this.ny) {
			if(!this.active) {
				this.nsy = this.fy/this.ty;
				var duration = (1.0 - this.nsy)*this.duration;
				var options = Object.extend({
					from: this.aperature.scrollTop,
					to:   this.ty,
					duration: duration,
					transition: this.transition
				}, {});
				this.start(options);
				this.active = true;
				this.aperature.style.cursor = 'pointer';
			}
		}
	},
	stopScroll: function() {
		if(this.active) {
				if(this.active) {
				this.cancel();
				this.active = false;
				this.aperature.style.cursor = 'auto';
			}
		}
	},
	endScroll: function(event) {
		var element = Event.element(event);
		this.py = Event.pointerY(event);
		this.px = Event.pointerX(event);
		if(!Position.within(this.aperature, this.px, this.py ))
			this.stopScroll();
	}
});