// Splintered striper 2.0
// 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.
// Patrick H. Lauke aka redux / www.splintered.co.uk
// Valentin Agachi / agachi.name
// Distributed under the Creative Commons Attribution-ShareAlike license - http://creativecommons.org/licenses/by-sa/2.0/
/*
 * Parameters:
 * parentElementTag - parent tag name
 * parentElementClass - class assigned to the parent; if null, all parentElementTag elements will be affected
 * childElementTag -  tag name of the child elements to apply the styles to
 * styleClasses - comma separated list of any number of style classes (using 2 classes gives the classic "zebra" effect)
 * hoverClasses - comma separated list of styles classes to be applied on hover (default: none)
 * 
 * Return: none
 */
function striper(parentElementTag, parentElementClass, childElementTag, styleClasses, hoverClasses) {
	var i=0,currentParent,currentChild;
	if ((!document.getElementsByTagName)||(!parentElementTag)||(!childElementTag)||(!styleClasses)) return false;
	var styles = styleClasses.split(',');
	var stylesHover = styles;
	if (hoverClasses) stylesHover = hoverClasses.split(',');
	var parentItems = document.getElementsByTagName(parentElementTag);
	while (currentParent = parentItems[i++]) {
		if ((parentElementClass == null)||(new RegExp('\\b'+parentElementClass+'\\b').test(currentParent.className))) {
			var j=0,k=0;
			var childItems = currentParent.getElementsByTagName(childElementTag);
			while (currentChild = childItems[j++]) {
				k = (j+(styles.length-1)) % styles.length;
				currentChild.className = currentChild.className+" "+styles[k];
				if (hoverClasses) {
					currentChild.onmouseover = new Function("this.className+=' "+stylesHover[k]+"';");
					currentChild.onmouseout  = new Function("this.className=this.className.replace(' "+stylesHover[k] + "','');");
				}
			}
		}
	}
}
