/*
======== table of content. =================================

summary: add background-color table cell as stripe

============================================================
*/

new function(){
	
	var className = 'stripe';
	var color = '#F9F9F9';
	
	var isMSIE = /*@cc_on!@*/false;
	
	function addStripe() {
		
		var tableElement = document.getElementsByTagName('table');
		var len = tableElement.length;
		
		for ( var i=0; i<len; i++ ) {
			if ( hasClass( tableElement[ i ], className ) ) {
				addStripeTable( tableElement[ i ] );
			}
		}
	}
	
	function addStripeTable( _table ) {
		
		var tbody = _table.getElementsByTagName('tbody')[ 0 ];
		var lines = tbody.getElementsByTagName('tr');
		var len = lines.length;
		
		for ( var i=0; i<len; i++ ) {
			if ( i%2 > 0 ) {
				addBgColor( lines[ i ] );
			}
		}
	}
	
	function addBgColor( _tr ) {
		
		var cells = _tr.getElementsByTagName('td');
		var len = cells.length;
		
		for ( var i=0; i<len; i++ ) {
			
			if ( ! cells[ i ].getAttribute( 'bgcolor' ) ) {
				cells[ i ].style.backgroundColor = color;
			}
			
		}
	}
	
	function hasClass( _dom, _class ) {
		
		var classes = isMSIE ? _dom.getAttribute('className') : _dom.getAttribute('class');
		
		if ( classes ) {
			var temp = classes.split(' ');
			var len = temp.length;
			
			for ( var i=0; i<len; i++ ) {
				if ( temp[ i ] == _class ) {
					return true;
				}
			}
		}
		
		return false;
	}
	
	if(window.addEventListener) {
		window.addEventListener('load', function(_e){ addStripe(); }, false);
	}
	else if(window.attachEvent) {
		window.attachEvent('onload', function(_e){ addStripe(); });
	}
}

