Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ok, I finally solved it. First, I had to make the pois layer a global variable to access it from an external function (thanks Thomas!). Second, it turns out I was trying to access what I thought was an attribute, when in fact it was an externalGrahics link. Once I figured that out, the rest worked as I wanted. I have added the solution to the original question.
You are correct that my JavaScript skills are weak. I will try to improve. However, this is only a part of the whole project, which is coded in php, asp and sql. So forgive me for trying to cut some corners as to learning yet another code language. Still, thanks for pointing out the major error!