// Copyright (C) 2007-2008 Stephane Lavergne <http://www.imars.com/>
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.

// Zebra tables
//
//	Every block of class 'zebra' which contains 'tr' or 'dt' and 'dd' elements
//	will have their odd rows set to class 'odd'.
//
//	zebra() can optionally be provided with a node to (re)scan that node for
//	zebras, useful for dynamically generated content.

imars.require("imars.dom");

imars.dom.zebra = function (doc) {
	if (!doc) doc = document;
	if (doc.getElementsByTagName) {
		var bs = imars.dom.getElementsByClassName(doc, '*', 'zebra');
		var bCount = bs.length;
		var rns = [ 'tr', 'dt', 'dd' ];
		var rnCount = rns.length;
		for (var i=0; i < bCount; i++) {
			for (var j=0; j < rnCount; j++) {
				var rs = bs[i].getElementsByTagName(rns[j]);
				var rCount = rs.length;
				for (var k=0; k < rCount; k++) {
					if (k % 2) rs[k].className = 'odd';
				};
			};
		};
	};
};

imars.onLoad(imars.dom.zebra);
