$$DeviceID and $DeviceID are not the same variable. You use one with Get ( Device) and the other in your if step and so your script fails to work.
$$ Variables live for the life of the application.
$ Variables live for the life of the script.
As philmodjunk points out you are setting a $$Variable and using a $Variable which are two different things.
And you set $DistTop then use $WinDistTop.
Thank you guys... sometimes its the easy stuff that gets you! Its working now. Yes, I know the difference between a local and global variable, but sometime we are blind to the most obvious things! ;-)