// Splintered Striper
// reworking of Zebra Tables and similar methods which works not only for tables and even/odd rows,
// but as a general DOM means of assigning any number of classes to children of a parent element.
// (C)2005 Patrick H. Lauke aka redux / www.splintered.co.uk

/* core function for this experiment */
function splinteredStriper(parentElementTag, parentElementClass, childElementTag, styleClasses)
{
	// All parameters are strings; styleClasses contains a comma-separated list of N styles.
	// If parentElementClass is null, the styling will be applied to the child elements regardless of class assigned to the parent element in the markup
	// Usage example: to add alternating oddRow/evenRow classes to rows of a table with class="striped"
	// splinteredStriper('table','striped','tr','oddRow,evenRow')
	var styles = styleClasses.split(',');
	var i=0;
	var parentItems = document.getElementsByTagName(parentElementTag);
	var currentParent;
	while (currentParent = parentItems[i++]) {
		if ((parentElementClass == null) || (currentParent.className == parentElementClass)) {
			var j=0;
			var k=0;
			var childItems = currentParent.getElementsByTagName(childElementTag);
			var currentChild;
			while (currentChild = childItems[j++]) {
				k = (j+(styles.length-1)) % styles.length;
				currentChild.className = styles[k];
			}
		}
	}
}


/* addEvent handler for IE and other browsers */
function addEvent(elm, evType, fn, useCapture)
{
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
} 


/* wrapper function that will be attached to the document */
function stripe()
{
	splinteredStriper('ul','zebraList','li','oddcolor,evencolor');
	splinteredStriper('table','zebraTable','tr','oddcolor,evencolor');
	splinteredStriper('dl','zebraDefinition','dd','oddcolor,evencolor');
	
}

/* attach the wrapper function to the window's onload event */

addEvent(window,'load',stripe);
