(function () {
    "use strict";

    function addOpenIdEnabledLink() {
        var html, $label, $children;

        jQuery('#commentForm').addClass('openid');

        html =  ' <a id="openid_enabled_link" href="http://openid.net">(OpenID Enabled)</a> ' +
            '<div id="openid_text">' +
            'If you have an OpenID, you may fill it in here.  If your OpenID provider provides ' +
            'a name and email, those values will be used instead of the values here.  ' +
            '<a href="http://openid.net/what/">Learn more about OpenID</a> or ' +
            '<a href="http://openid.net/get/">find an OpenID provider</a>.' +
            '</div> ';

        jQuery('#commentForm #url').attr('maxlength', '100');
        $label = jQuery('#commentForm label[for=url]');
        $children = jQuery(':visible', $label);

        if ($children.length > 0) {
            $children.filter(':last').append(html);
        } else if ($label.is(':hastext')) {
            $label.append(html);
        } else {
            $label.append(html);
        }

        // setup action
        jQuery('#openid_text').hide();
        jQuery('#openid_enabled_link').click(function () {
            jQuery('#openid_text').toggle(200);
            return false;
        });

    }

    $(function () {
        addOpenIdEnabledLink();
    });
}());
