Take a look at http://de.wikipedia.org/wiki/Floodfill
Insteat of color comparisons you have to do filename comparison. Apart from that it´s pretty straightforward.


no science involved