/**
 * http://www.jobcn.com/
 * By zhangping
 *
 * For: IE6,IE7,Firefox	
 * 
 * Required : rgbcolor.js
 */
	
	
	var TableAlternationConfig = {
		id : 'table_alternation', //表格元素id
		odd:  '#FFF', //基数行背景色
		even: '#FFF7F0', //偶数行背景色
		hover: '#C8CA74',  //鼠标停留背景色，为false不添加鼠标动作
		index: 0 ,		//起始行行标
		remain: 0 , 	//保留最后不处理的行数
		alterNum: 1		//间隔行数
	}
	
	function TableAlternation(config){		
		config = config || new Object();
		for(var prop in TableAlternationConfig) { 
			if(config[prop]==null) config[prop]=TableAlternationConfig[prop];	
		}
		
		var table = document.getElementById(config.id); 		
		if(!table || !table.rows) return null;
	  
	  var colors = new Array();			
		var count = 0;	 
	  var rowsNum = table.rows.length - config.remain;
	  
	  for(var i=config.index; i<rowsNum; i++){
	  	count++;
	   	colors[i] = (count>config.alterNum)? config.even : config.odd;	   	  
	    if(count >= config.alterNum * 2) count = 0;
	  }
	  
	  for(var i=config.index; i<rowsNum; i++){
	  	if(colors[i]) table.rows[i].style.backgroundColor = colors[i];	  	
	    if(config.hover && colors[i]){
	    	table.rows[i].onmouseover = mouseOverAlternate;    	
	    	table.rows[i].onmouseout  = mouseOutAlternate; 
	  	}
	  }
	  
	  function mouseOverAlternate(){
	  	if(config.alterNum==1) { this.style.backgroundColor = config.hover; return; };
  		var start = this.rowIndex - config.alterNum + 1;
  		start = start<config.index ? config.index :start;
  		var end = this.rowIndex + config.alterNum - 1; 
  		end = end > rowsNum-1 ? rowsNum-1 : end;  		
  		var backgroundColor = this.style.backgroundColor;  		
  		for(var j=start; j<=end; j++){
  			if(new RGBColor(backgroundColor).toHex() == new RGBColor(colors[j].toLowerCase()).toHex())
  				table.rows[j].style.backgroundColor = config.hover; 
  		}  		
	  }
	   
		function mouseOutAlternate(){
			if(config.alterNum==1) { this.style.backgroundColor = colors[this.rowIndex]; return; };
			var start = this.rowIndex - config.alterNum + 1;
  		start = start<config.index ? config.index :start;
  		var end = this.rowIndex + config.alterNum - 1; 
  		end = end > rowsNum-1 ? rowsNum-1 : end;  
  		var backgroundColor = this.style.backgroundColor;		
  		for(var j=start; j<=end; j++){
  			if(new RGBColor(backgroundColor).toHex() == new RGBColor(config.hover.toLowerCase()).toHex())
  				table.rows[j].style.backgroundColor =colors[j]; 
  		}
		}			
	}
	