Haskell, 5252 49 bytes
map(\x->head$[-1|x<2]++[d|d<-[x-1,x>last$[d|d<-2[1..]x-1],mod x d<1]d<1]++[-1|x<2]) map -- for each element in the input array \x-> -- apply the lambda function headlast -- pick the firstlast element of the following list [[d|d<-1|x<2]++[1..x-1] -- all d --from 1 to x-1 if x<2, followed by [d|d<-[x-1 ,mod x-2..] d<1] -- all d from x-1where downd todivides negativex infinity ++[-1|x<2] ,mod x d<1] -- wherefollowed dby divides-1 xif x<2