the file looks fine.. the only place i can see that a division by zero error would occur is with the modulus operator (%), and that means $tab_color would have to be zero which makes no sense as tab_color is a global here. Only thing i can think of is on line 62 put: