// Text readability
// version 0.1 WIP!
// 2008-12-09
// Copyright (c) 2008, Skyfire
// Released under the XXX license / copyright ?
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          Text readability
// @namespace     http://skyfire.com/
// @description   increase font size of relevant text block in a webpage
// @include       *
// ==/UserScript==

var paragraphs, p;

var sibling_paragraphs = new Array();

// get all <p> in the page.
paragraphs = document.getElementsByTagName('p');

// create a bidimentional table containing rows of sibling <p>'s
if(paragraphs && paragraphs.length) {
	for(var i = 0; i < paragraphs.length; i++) {
		p = paragraphs[i];
		// check for p's father: if its parent has not been found so far, 
		// add it in sibling_paragraphs. Otherwise, just put it in the proper list 
		// of siblings
		
		find_parent(p);
	}
}

function find_parent(p) {

	// we walk through the sibling_paragraphs array comparing if p's parent node is the same
	// as sibling_paragraphs[i] [0]'s parent
	// { 
	// 	if (we reach the end of the array w/out success)
	// 		we put add the p into a new position in sibling_paragraphs. 
	// 	else
	//		put p in the end of sibling_paragraphs[i] 
	// }

	var success = false;
	
	for(var i = 0; i < sibling_paragraphs.length; i++) {

		// compare parent nodes
		if(sibling_paragraphs[i] && sibling_paragraphs[i][0]) {
			if(p.parentNode == sibling_paragraphs[i][0].parentNode) {
				// add it in the end.
				var cur_length = sibling_paragraphs[i].length;
				sibling_paragraphs[i][cur_length] = p;
				success = true;
				break;
			}
		}
	}
	
	if(!success) {
		sibling_paragraphs[sibling_paragraphs.length] = new Array(p);
	}
}
