if (!livedoorProfileNickname){
    var livedoorProfileNickname = function (l_id, elm_id, charset) {
        this.base_url = "http://portal.profile.livedoor.com/";
        this.charset = charset ? charset : 'euc-jp';
        this.l_id = l_id;
        if (elm_id)
            this.elm_id = elm_id;
        else {
            this.elm_id = "livedoor_profile_nickname_" + Math.random().toString(36).slice(2);
            document.write("<span id='"+this.elm_id+"' class='ldProfileNickname'></span>");
        }
        var obj = this;
        setTimeout(function () { obj.getNickname(); }, 100);
    };
    livedoorProfileNickname.prototype = {
        getNickname : function () {
            var api_url = this.base_url+"api/user/nick?"+this.queryString({
                livedoor_id : this.l_id, oe : this.charset, uniq : Math.random().toString(36).slice(2)
            });
            var obj = this;
            this.callJSONP(api_url, function (json) {
                try {
                    var nick = json.status == 'success' ? json.nick : obj.l_id;
                    document.getElementById(obj.elm_id).appendChild(document.createTextNode(nick));
                } catch (e) {}
            });
        },
        callJSONP : function (api_url, cb_func) {
            var uniq_name = "ld_profile_callback_" + Math.random().toString(36).slice(2);
            var scr = document.createElement("script");
            scr.type = "text/javascript";
            scr.charset = this.charset;
            scr.src = api_url + '&callback=' + uniq_name;
            scr.id = uniq_name;
            var obj = this;
            window[uniq_name] = function (json) {
                cb_func(json);
                var u_name = uniq_name;
                var obj2 = obj;
                setTimeout(function() {
                    obj2.head.removeChild(document.getElementById(u_name));
                    try{
                        window[u_name] = null;
                        delete window[u_name];
                    } catch (e) {};
                }, 200);
            };
            obj.head = document.getElementsByTagName("head").item(0);
            setTimeout(function(){ obj.head.appendChild(scr); }, 100);
        },
        queryString : function (q) {
            var res = [];
            for (var i in q)
                res.push(i + "=" + encodeURIComponent(q[i]));
            return res.join("&");
        }
    };
}
