I think this isn't doing what you expect it to be doing.

I'd go with

```js
if (layer instanceof OpenLayers.Layer.UTFGrid ||
    layer instanceof OpenLayers.Layer.UTFGridWMS) {
// ...
}
```