var Buttonr = {
    start: function() {
        var buttons = document.getElementsByClassName('hoverbutton');
        for (var i = 0; i < buttons.length; i++) {
            var index = -1;
            if (buttons[i].src) {
                this.addprops(buttons[i]);

                buttons[i].stopObserving('mouseout', buttons[i]._mouseout);
                buttons[i].stopObserving('mouseover', buttons[i]._mouseover);
                buttons[i].stopObserving('mousedown', buttons[i]._mousedown);

                buttons[i].observe('mouseout', buttons[i]._mouseout);
                buttons[i].observe('mouseover', buttons[i]._mouseover);
                buttons[i].observe('mousedown', buttons[i]._mousedown);
            }
        }
    },

    mouseout: function() {
        Buttonr.addprops(this);
        if (this._src) {
            this.src = this._src;
        }
    },

    mouseover: function() {
        Buttonr.addprops(this);
        if (this._mouseoverSrc) {
            this.src = this._mouseoverSrc;
        }
    },

    mousedown: function() {
        Buttonr.addprops(this);
        if (this._mousedownSrc) {
            this.src = this._mousedownSrc;
        }
    },

    addprops: function(el) {
        var index;
        if (el.src && !el._src && (-1 != (index = el.src.lastIndexOf('.')))) {
            var src = el.src;
            el._src = src;
            el._mouseoverSrc = src.substr(0, index) + '_mouseover' + src.substr(index);
            el._mousedownSrc = src.substr(0, index) + '_mousedown' + src.substr(index);

            el._mouseout = this.mouseout.bindAsEventListener(el);
            el._mouseover = this.mouseover.bindAsEventListener(el);
            el._mousedown = this.mousedown.bindAsEventListener(el);
        }
    }
}

Event.observe(window, 'load', Buttonr.start.bindAsEventListener(Buttonr));