most chams change color, due to either horomonal reasons, ie breeding, or to show domminace to other males, as well females will change to show receptive as well as gravid colors, they acctually do not change to blend into their souroundings.
The color changing ability is caused by distribution of melanin (color pigment) in the scales. There are 3 different types of color producing scales (chromatophores) which is why you see such variation. Xanthophores are the most superficial layer and are responsible for yellow and red. Melanophores are under those and responsible for black. Guanophores are the deepest and reflect blue light. When the melanophores have evenly distributed melanin your cham appears darker, and when it's concentrated in one focal area it allows the other colors to be more prominent. (referenced from Necas' "Chameleons - Nature's Hidden Jewels")
Based on their mood and environment the melanin can be widely distributed throughout the scale, causing one color, or very concentrated in one spot or at the surface of the scale, causing a different color. It varies their mood and environment. A constantly dark cham may indicate chronic stress, fear or illness. Whereas a light colored cham may mean contentment. And the super brightly colored chams may be breeding colors or a method of intimidation (when my veiled is the brightest).
Necas also mentioned in one of his books that chameleons raised around dark colors that might not appear in their native habitat (like reds) may actually cause them to have darker colors as adults than babies raised around a lot of green, which I thought was interesting.
They have a limited ability to match their surroundings, and only if it's within their color range. A panther chameleon would never be blending well with a stick for instance, they don't naturally show brown. Notice that all the pictures posted are of different species. It's not one chameleon changing to adapt to all those environments. They mimic the movement (or lack thereof) of their surroundings when trying to hide, and they will usually display drab colors so as not to stand out. It works well in the favor when their drab colors happen to match what they're on (a natural adaptation) but they can't change drastically to match it. And it's certainly to the extent that they will just change to match anything. Even a panther who can show blue won't necessarily flood with blue if you put him on a blue object. Or turn checkerboard on a checkerboard like they do in cartoons. I think that's more the sarcasm Sensation was referencing.
Hey thought I would revive this post with a question, how often does your cham change color and why do you think it does?
I have a pygmy cham I just got and introduced lighter branches into his habitat. Now he is streaking with lighter browns. Think he may be trying to blend in? Don't think he is stressed as he has been quietly sleeping for a while now.