Hello, i have this square 7x7 where each row is clickable in it.

If row is clicked i want it to make 3x3 block around it (and it kinda work) if it is possible if not mark only available rows as marked.

It works grate until i try to use row a-1 to row a-7 or rows a-1, b-1, c-1, d-1, e-1, f-1 and g-1

Here is a demo: http://phpfiddle.org/main/code/z5bj-au6i

Try to click around and you will see that it generates 3x3 blocks or for example on g-7 2x2 witch is correct but if you try g-1 for example you see that something breaks!

I cant figure out the best method to solve this! Any help?

Thanks in advance!