This is mostly a string problem.
Remember that double quotes and single quotes don't match each other. When you set the source to "'+p1.src+'", you're setting it to
'+p1.src+'
since there are no double quotes inside your double-quoted string. And since there are no images called '+p1.src+' anywhere, it can't load the image.
Here's what you want to do. You want the source to be p1.src, so merely set it like this:
document.getElementById('pic').src = p1.src;
It seems that what you're trying to do right now is set it to "" + p1.src + "", but adding those extra empty strings on either side is unecessary. Because they're empty.
Now, you also have to set id="pic" inside your image tag for that to reference the correct element. And also, your function tests if(what == 1), and you're calling it as cambia(5). You'll either need to change the 1 to a 5, or the 5 to a 1. If they don't match, the function won't do anything.