var server_connection_state = true;

var pinger = function()
{
    $.ajax( {
        url: '?action=ping',
        success: function()
        {
            if( server_connection_state == false )
                toastr.success( 'Server reachable again' );
            
            server_connection_state = true;
            return setTimeout( pinger, 30000 );
        },
        error: function()
        {
            if( server_connection_state == true )
                toastr.error( 'No connection with the server' );
            
            server_connection_state = false;
            return setTimeout( pinger, 1000 );
        }
    } );
}

setTimeout( pinger, 5000 );
