Можно сделать через атрибуты (грязно, но просто) или через замыкания (сложно, зато семантически правильно).
Через атрибуты:
<script>
function toggleM(img) {
var m= +img.getAttribute("m");
var a= +img.getAttribute("a");
m+=a;
a=-a;
alert(m);
img.setAttribute("m", m);
img.setAttribute("a", a);
};
</script>
<img src='http://javascript.ru/forum/images/ca_serenity/misc/logo.gif' onclick='toggleM(this)' width="200" m="10" a="5"/>
<img src="http://img.yandex.net/i/www/logo.png" onclick="toggleM(this)" width="200" m="7" a="3" />