// ==UserScript==
// @name        ldr_wheelhack
// @namespace	http://ma.la/
// @include     http://reader.livedoor.com/reader/*
// @version     1.0
// ==/UserScript==


// Opera でも動くように
// remain の値の判定が怪しい。

(function(){
//	var w = window;
//	var _onload = w.onload;

	// 次のフィードに移動するまでに必要なカウント量
	var asobi = 30;
	var asobi_count = {};
	var reset_asobi = function(){
		asobi_count = {
			prev : 0,
			next : 0
		};
	};
	reset_asobi();

	var onload = function(){with(window){
		var target = $("right_container");
//		Event.observe(target, "DOMMouseScroll", function(e){
		Event.observe(target, "mousewheel", function(e){ // Opera用
			if(target.scrollTop == 0 && e.detail < 0){
				asobi_count.prev += Math.abs(e.detail);
				asobi_count.next = 0;
				// message(asobi_count.next);
				if(asobi < asobi_count.prev){
					Control.read_prev_subs();
					Event.stop(e);
					reset_asobi();
					return;
				}
			}
			var remain = target.scrollHeight - target.clientHeight - target.scrollTop;
			// writing_complete 描画完了待ち
            // 16 ってのは 横スクロールバー分だと思われる
			if(writing_complete() && remain == 16 && e.detail > 0){
				asobi_count.next += Math.abs(e.detail);
				asobi_count.prev = 0;
				// message(asobi_count.next);
				if(asobi < asobi_count.next){
					Control.read_next_subs();
					Event.stop(e);
					reset_asobi();
					return;
				}
			}
		});
	}}

    window.addEventListener('load', onload, false);
})();
