Simple color flooding game in Javascript/HTML5 canvas area
This would be so much easier with the use of a table or divs. You could then create an array of objects (one object per square). Ex: 

[
    {
        "className": "orange",
        "x": 0,
        "y": 0
    }
];


By doing this, you can match the class of the surrounding objects, rather than changing the color directly. Hope this helps.