init(); function init() { var jsImgButton; jsImgButton = document.getElementsByName("jsimgbutton"); for(var i=0; i < jsImgButton.length; i++) { jsImgButton[i].onmouseover = jsImgButton[i].onmouseup = jsImgButton[i].onmouseout = jsImgButton[i].onmousedown = ButtonState; } } function ButtonState(evt) { if( !evt) evt = event; else evt.srcElement = evt.target; var btnWidth = parseInt(evt.srcElement.style.width); if (evt.srcElement.style.backgroundPosition == '-250px 0px') { //already clicked } else { if(evt.srcElement.disabled) return if(evt.type == "mouseover" ) //evt.srcElement.style.backgroundPosition = "-" + btnWidth+ "px 0px"; if(evt.type == "mouseout" ) //evt.srcElement.style.backgroundPosition = "0px 0px"; if(evt.type == "mousedown" ) evt.srcElement.style.backgroundPosition = "-" + btnWidth * 2 + "px 0px"; if(evt.type == "mouseup" ) evt.srcElement.style.backgroundPosition = "-" + btnWidth+ "px 0px"; } }