// ==UserScript==
// @name          Fix j in Bloglines
// @namespace     http://www.tobez.org/download/greasemonkey/
// @description   Fix `j' - "go to next article" shortcut in Bloglines for larger font sizes
// @include       http://www.bloglines.com/*
// ==/UserScript==

/**
 ** bloglines-fix-j.user.js version 0.04
 **
 ** ----------------------------------------------------------------------------
 ** "THE BEER-WARE LICENSE" (Revision 42)
 ** <tobez@tobez.org> wrote this file.  As long as you retain this notice you
 ** can do whatever you want with this stuff. If we meet some day, and you think
 ** this stuff is worth it, you can buy me a beer in return.   Anton Berezin
 ** ----------------------------------------------------------------------------
 **
 ** Bloglines has recently introduced very nice keyboard shortcuts
 ** to jump around the feeds.  Unfortunately, the `j' shortcut (go to the
 ** next article) is broken for larger font sizes.  Hopefully, Bloglines
 ** team will fix this soon.  Meanwhile, for your enjoyment, this script
 ** does the job.
 ** 
 **/

(function() 
{
	function my_version_of_goto_next_item(dummy) {
		var pos;
		var documentPosY = window.pageYOffset;
 
		for (var i=0; i < document.anchors.length; i++) {
			if( document.anchors[i].name.substring(0, 8) == "article-" ) {
				pos = getAnchorPosition(document.anchors[i]);
				if( pos > documentPosY + document.anchors[i].nextSibling.offsetHeight) {
					currentArticleIndex = i;
					break;
				}
			}
		}
		window.location.hash=document.anchors[currentArticleIndex].name;
		return;
	}
	
	function fix_j_for_large_fonts() {
		var w = window.unsafeWindow ? unsafeWindow : window;
		if (typeof w.gotoNextItem != undefined)
			w.gotoNextItem = my_version_of_goto_next_item;
	}
	
	fix_j_for_large_fonts();
})();
