if ( !livedoorClipProfile ) {
    var livedoorClipProfile;
    (function () {
        var ld_prof_clip_profile = function () {};
        ld_prof_clip_profile.prototype = {
            write : function (livedoor_id) {
                this.livedoor_id = livedoor_id;
                this.base_url = 'http://portal.profile.livedoor.com/';
                this.elm_id = "ld_profile_" + Math.random().toString(36).slice(2);
                document.write('<div id="'+this.elm_id+'"></div>');
                var obj = this;
                setTimeout(function () { obj.loadProfile(); }, 100);
            },
            loadProfile : function () {
                var api_url = this.base_url+"api/user/profile?"+this.queryString({
                    livedoor_id : this.livedoor_id, oe : 'eucjp', uniq : Math.random().toString(36).slice(2)
                });
                var obj = this;
                this.callJSONP(api_url, function (json) {
                    try {
                        obj.elm = document.getElementById(obj.elm_id);
                        if ( json.status == "success" ) {
                            var cfg = {
                                'img_size' : "60",
                                'img'      : 1,
                                'name'     : 1,
                                'intro'    : 1
                            };                            
                            var profile_div = document.createElement('div');
                            profile_div.className = "profbody";

                            var img_div = document.createElement('div');
                            img_div.className = "photo";
                            var img_link = document.createElement('a');
                            img_link.href = json.profile_url;
                            var img = document.createElement('img');
                            img.src = json.icon[cfg.img_size];
                            img.style.border = "none";
                            img_link.appendChild(img);
                            img_div.appendChild(img_link);
                            profile_div.appendChild(img_div);

                            var name_div = document.createElement('div');
                            name_div.className = "nickname";
                            var name = document.createElement('a');
                            name.href = json.profile_url;
                            name.appendChild(document.createTextNode(json.nickname));
                            name_div.appendChild(name);
                            profile_div.appendChild(name_div);

                            var intro = document.createElement('div');
                            var intro_message = json.profile.introduction ? json.profile.introduction : "";
                            intro.className = "message";
                            intro.innerHTML = intro_message;
                            profile_div.appendChild(intro);

                            obj.elm.appendChild(profile_div);
                        }
                        else
                            obj.elm.innerHTML = "プロフィール未設定";
                    } 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 = "euc-jp";
                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("&");
            }
        };
        livedoorClipProfile = new ld_prof_clip_profile();
    })();
}
