selecting frontmost document window

Hi all,
I’ve tried to get name of frontmost document window but instead got an name of app palette which has user focus. Is any way to separate palettes (they are windows too) from real document windows?

tell application "System Events"
		tell process currApp to set a to windows
...

the problem arises when this block included into on idle section. Other words, when I test script in Script Debugger all seem OK, but when I enable on idle and test script in real life, var “a” hold a list of all UI elements

Any ideas?