var timerID = 0;
var TOut = 0;
var filters = new Array( new Array( '1.8', '3.5', '7.0', '10.0', '14.0', '18.0', '21.0', 
                                    '24.8', '28.0' ),
                        new Array( '50.0-54.0', '70.0-71.0', '144.0-148.0', '430.0-440.0', 
                                    '1200.0-1300.0', '2300.0-2500.0', '5600.0-6000.0', 
                                    '10000.0-11000.0', '24000.0-24300.0') );   

function enableRow( row ) {
    if ( !$( '#cb_row' + row.toString() ).attr( 'checked' ) ) {
        for ( co = 0; co < filters[ row ].length; co++ ) {
            $( '#cs' + row.toString() + co.toString() ).html( '' );
        }
    } else {
        showRow( row );
    }
}

function enableDx() {
    if ( !$( '#cb_dx' ).attr( 'checked' ) ) {
        $( '#dx_data' ).html( '' );
    } else {
        showDx();
    }
}

function showDx(){                                                                       
    $( '#dx_data' ).load( "cache/shdx" );
}                                                                                           

function showRow( row ) {
    for ( co = 0; co < filters[ row ].length; co++ ) {
        showCS( 'cs' + row.toString() + co.toString(), filters[ row ][ co ], row );
    }
}

function showCS( id, filter, row ){       
    $.ajax( {
        url: "cache/" + filter, 
        success: function(data) { 
            if ( $( '#cb_row' + row.toString() ).attr( 'checked' ) ) {
                $( '#' + id ).html( data );
                $( '#' + id +' li' ).hover( function() {
                    $( this ).addClass( "hover" );
                }, 
                function() {
                    $( this ).removeClass( "hover" );
                } ); 
            }
        } 
    } );
}
       
function reload() {
    var row, co;
    for ( row = 0; row < filters.length; row++ ) {
        if ( $( '#cb_row' + row.toString() ).attr( 'checked' ) ) {
            for ( co = 0; co < filters[ row ].length; co++ ) {
                showRow( row );
            }
        }
    }
    if ( $( '#cb_dx' ).attr( 'checked' ) ) {
        showDx();
    }
    setTOut( TOut );
}

function setTOut( val ) {
    if ( timerID ) {
        clearTimeout( timerID );
    }
    TOut = val;
    if ( TOut > 0 ) {
        timerID = setTimeout("reload()", TOut); 
    }
}

$( document ).ready( function() {
   TOut = parseInt( $( ":radio[ name = 'refresh_rb' ]:checked" ).val() );
   reload();
} );
