(function($){
    
    $.fi = {};
    $.fi.suomiyhtio = {};

    $.fi.suomiyhtio.table_enhancements = {
        tables: null,
        config: {
            overColor: '#DBDFE5',
            hoverClass: 'cellFormat_hover'
        }
    };
    $.extend($.fi.suomiyhtio.table_enhancements, {
        init: function(tables) {
            var _self = this;
            
            this.tables = [];            
            
            $.each(tables, function(){
                var table = $(this);
                _self.tables.push(table);
                
                $.each($('tbody tr', table), function(){                    
                    _self._set_tr_mouseovers($(this));
                });                
            });
            
            $.fi.suomiyhtio.table_enhancements.tables = this.tables;
            
            return this;
        },
        _set_tr_mouseovers: function(row) {
            var orig_color = '';
            var _self = this;
            row.bind('mouseover', function(){
                orig_color = row.css('background-color');
                row.css('background-color', $.fi.suomiyhtio.table_enhancements.config.overColor);
                _self._update_cells_onhover(row);
            });
            row.bind('mouseout', function(){
                row.css('background-color', orig_color);
                _self._update_cells_onout(row);
            });
        },
        _update_cells_onhover: function(row) {
            $.each($('td', row), function(){
                $(this).addClass($.fi.suomiyhtio.table_enhancements.config.hoverClass);
            });
        },
        _update_cells_onout: function(row) {
            $.each($('td', row), function(){
                $(this).removeClass($.fi.suomiyhtio.table_enhancements.config.hoverClass);                
            });            
        }
    });
    
    $(document).ready(function(){
        $.fi.suomiyhtio.table_enhancements.init($('table.tableClass'));
    });

})(jQuery);
