/**
 * This startup script initializes zebra tables
 * 
 * All tables with class attribute "zebra" are marked
 * in the described way:
 * 
 * All odd trs are marked with class "odd" and all even
 * tables are marked with class "even" analog.
 * 
 * Trs which contain th-tags are ignored completely and
 * after the occurance of any th-containing tr tag the
 * marking of the next rows will start with odd again.
 */
window.addEvent('domready', function() {
	
	tables	=	$$('table.zebra');
	
	for (i = 0; i < tables.length; ++i) {
		table	=	$(tables[i]);
		
		trs		=	table.getElementsByTagName('tr');
		loop	=	0;
		
		for (j = 0; j < trs.length; ++j) {
			tr	=	trs[j];
			
			// If row has a ths inside, it will be ignored
			// and loop will be reset
			ths	=	tr.getElementsByTagName('th');
			if (ths.length > 0) {	
				loop = 0;			
				continue;
			}
			
			// If the first td has class "head" the entire row will be ignored
			tds	=	tr.getElementsByTagName('td');
			if (td = tds[0]) {
				mytd	=	$(td);
				if (mytd.hasClass('head')) {
					continue;
				}
			}
						
			if (loop % 2 == 0) {
				$(tr).addClass('odd');
			}
			else {
				$(tr).addClass('even');
			}
			
			++loop;
		}
	}	
});