Javascript implementation of: http://digestingduck.blogspot.com/2010/03/simple-stupid-funnel-algorithm.html