Theory of percolation and tunneling regimes in nanogranular metal films