(function ($) {
    function section508() {
        var opts = this.textbox("options");
        for (var i = 0, icons = opts.icons; i < icons.length; i++) {
            this.textbox("getIcon", i).attr("aria-label", icons[i].iconCls);
        }

        var input = this;
        var tb = this.textbox("textbox");
        $.each(["aria-label", "aria-labelledby", "title"], function (_, name) {
            var attr = input.attr(name);
            attr && tb.attr(name, attr) && input.removeAttr(name);
        });

        var tbid = tb.attr("id");
        var id = this.attr("id");

        if (!opts.label && id && tbid != id) {
            this.parent().find("label").each(function () {
                var l = $(this);
                if (l.attr("for") == id) {
                    l.attr("for", tbid);
                    return false;
                }
            });
        }

        if (input.is(":hidden")) {
            input.attr("aria-hidden", "true");
        }
    }

    var plugin = $.fn.textbox;
    $.fn.textbox = function (opts, params) {
        if (typeof opts == "string") {
            return plugin.call(this, opts, params);
        } else {
            return this.each(function () {
                plugin.call($(this), opts, params);
                section508.call($(this));
            });
        }
    };
    $.fn.textbox.defaults = plugin.defaults;
    $.fn.textbox.parseOptions = plugin.parseOptions;
    $.fn.textbox.methods = plugin.methods;
})(jQuery);

(function($) {
    function section508() {
        if (this.is("a")) {
            this.attr("role", "button").on("keypress", function (e) {
                if (e.which == 32) {
                    this.triggerHandler("click");
                    e.preventDefault();
                }
            });
            var opts = this.linkbutton("options");
            if (opts.iconCls && !opts.text) {
                this.attr("aria-label", opts.iconCls);
            }
        } else if (this.is("button")) {
            this.on("keypress", function (e) {
                if (e.which == 32) {
                    e.preventDefault();
                }
            });
        }
    }

    var plugin = $.fn.linkbutton;
    $.fn.linkbutton = function (opts, params) {
        if (typeof opts == "string") {
            return plugin.call(this, opts, params);
        } else {
            return this.each(function () {
                plugin.call($(this), opts, params);
                section508.call($(this));
            });
        }
    };
    $.fn.linkbutton.parseOptions = plugin.parseOptions;
    $.fn.linkbutton.methods = plugin.methods;
    $.fn.linkbutton.defaults = plugin.defaults;
})(jQuery);