/**
 * StripyTable class
 * 
 * Will add even and odd classes to the rows of a table (only those in tbody if it exists)
 * These can then be styled with css externally
 * 
 */

Ah.StripyTable = function( table ){
    this.initialize( table );
}

Ah.StripyTable.prototype = {
    
    _table: null,
    _tbody: null,
    _oddClass: 'odd',
    _evenClass: 'even',
    
    initialize: function( table ){
        this._table = table;
        this._tbody = this._table.getElementsByTagName('tbody')[0];
        this._rows = this._getRows();
        this._stripe();
    },
    
    _getRows: function(){
        if(this._tbody){
            return this._tbody.getElementsByTagName('tr');
        }else{
            return this._table.getElementsByTagName('tr');
        }
    },
    
    _stripe: function(){
        for( var i = 0, len = this._rows.length; i < len; i++ ){
            var tr = this._rows[i];
            if(i % 2){
                tr.className += this._oddClass;
            }else{
                tr.className += this._evenClass;
            }
        }
    }
    
}
