Cycles: How can the camera position be removed from the Light Path node's Ray Length Related: How to get length of specific ray type and use that as color?

So the idea is to use the Light Path node's Ray Length to form the basis for ambient occlusion but the Camera position relative to the object is a part of the Ray Length info and this makes such a calculation difficult since this alter the results based on how far a specific position is to the camera.  

Here is a demonstration of what I mean.    

Here's a node setup that shows this effect.



For AO to work, this effect has to be cancelled out since the dirt and grime which tends to accumulate in crevices will not be affected by how far the viewer is from the object. 

So my question is this.  Does anyone have some ideas on how to remove the camera influence from the Ray Length result?
If you think about it, it's pretty easy; The way Booleans (true or false, not the modifier) are represented inside Blender by either 1 or 0; So if you do "1 - is Camera Ray", you will get ,basically, is NOT Camera Ray; if you multiply the Ray Length with is Not Camera Ray you will get the length for all rays except for the Camera ones. You could choose another Ray, and multiply it with Ray Length, to basicly get the length of that Ray.

Also note there's a Ambient Occlusion node.



After the part inside the box, you can use the rest of your material.