function mtUpdateSignInWidget(u) {
    var separator = '&nbsp;&nbsp;|&nbsp;&nbsp;';
    var el = document.getElementById('signin-widget-content');
    var content = '';
    if (!el) return;
    if (u) {
        if (u && u.is_authenticated) {
            user = u;
            mtSaveUser();
        } else {
            // user really isn't logged in; so let's do this!
            return mtSignIn();
        }
    } else {
        u = mtGetUser();
    }
    if (u && u.name) {
        var url;
        if (u.is_authenticated) {
            if (u.is_author) {
                url = 'http://kita2.net/mt/mt-cp.cgi?__mode=view&amp;blog_id=2';
                url += '&static=' + encodeURIComponent( location.href );
            } else {
                url = u.url;
            }
        } else if (u.url) {
            url = u.url;
        } else {
            url = null;
        }
        if (url)
            content += '<a href="' + url + '">' + u.name + '</a>';
        else
            content += '<span class="user_name">' + u.name + '</span>';
        if (u.is_author)
            content += separator + '<a href="http://kita2.net/mt/mt-cp.cgi?__mode=edit&amp;blog_id=2&amp;return_to=' + encodeURIComponent(document.URL) + '">ユーザー情報の編集</a>';
        
        content += separator + '<a href="javascript:void(0)" onclick="return mtSignOutOnClick()">サインアウト</a>';
        
    } else if (u && u.is_banned) {
        content = 'このブログにサインインする権限がありません。';
    } else {
        content = '<a href="javascript:void(0)" onclick="return mtSignInOnClick(\'signin-widget-content\')">サインイン</a>';
        content += separator + '<a href="http://kita2.net/mt/mt-cp.cgi?__mode=register&amp;blog_id=2&amp;return_to=' + encodeURIComponent(document.URL) + '">登録</a>';
    }
    el.innerHTML = content;
}
mtAttachEvent('load', mtUpdateSignInWidget);
mtAttachEvent('usersignin', mtUpdateSignInWidget);

