//global variables for all three examples
var colors = new Array('#ffffff','#dddddd','#aaaaaa','#888888');
var bgcolor = 255; 			//starting bgcolor in decimal
var steps = 10;				//the factor, a distance between colors
var down = true;			//direction, if going up or down when calculating bgcolor value
var switchingPoint = 160;	//the numeric value where the foreground color need to change
var fgColorHi = "white";
var fgColorLo = "black";
/****************************************************************************************/
function alternate(id){
	//method = document.methodSelector.selector[document.methodSelector.selector.selectedIndex].value;	
	if(document.getElementById){						//check that browser has capabilities
            var ids = id.split(","); 

   	    for (var j = 0 ; j < ids.length ; j++){

		var table = document.getElementById(ids[j]);		//get just the selected table not all of them
		var rows = table.getElementsByTagName("tr");	//get all table rows
		for(i = 0; i < rows.length; i++){				//alternate styles			
			//manipulate rows	
			// if(method == "doAlternate") 
                        doAlternate(rows[i], i);
			// if(method == "doMultiple") doMultiple(rows[i], i);
			// if(method == "doGradient") doGradient(rows[i]);
		}
            }
	}
}

/****************************************************************************************/
function doAlternate(row, i){
	if(i % 2 == 0){
		row.className = "even";
	}else{
		row.className = "odd";
	}
}
/****************************************************************************************/
function doMultiple(row, i){
	row.style.backgroundColor = colors[i % colors.length];
}
/****************************************************************************************/
function doGradient(row){
	useColor = document.methodSelector.color[document.methodSelector.color.selectedIndex].value;
	//build bgcolor string	
	if (useColor == "red")
		bgcolorValue = "ff" + padHex() + bgcolor.toString(16) + padHex() + bgcolor.toString(16);
	if (useColor == "green")
		bgcolorValue = padHex() + bgcolor.toString(16) + "ff" + padHex() + bgcolor.toString(16);
	if (useColor == "blue")
		bgcolorValue = padHex() + bgcolor.toString(16) + padHex() + bgcolor.toString(16) + "ff";
	
	row.style.backgroundColor = "#" + bgcolorValue;
		
	if(down && (bgcolor-steps) > 0){	//if subtracting, prevent negative values
		bgcolor = (bgcolor - steps);
	}else{							
		bgcolor = (bgcolor + steps);
		down = false;
	}
	if(bgcolor > 255){					//prevent too high values
		bgcolor = (bgcolor - steps);
		down = true;
	}
	if(bgcolor < switchingPoint){		//change color of text (foreground color) if below a certain value (160)
		row.style.color = fgColorHi;
	}else{
		row.style.color = fgColorLo;
	}
}
/****************************************************************************************/
function padHex(){
	return (bgcolor < 16) ? "0" : "";
}
/****************************************************************************************/



