jQuery.noConflict()
jQuery(function () {
    window["contentsLoader"] = new function () {
        var $jtemplates = jQuery.createTemplateURL("/js/jquery/templates/sbm_merge.txt", null, {
                        filter_data : false
        });
        var no_comment  = "<div class='no-comment-style'>コメントがありません。</div>";
        return {
           "clip" : {},
           "hatena" : {
                 url      : "http://b.hatena.ne.jp/entry/json/",
                 callback : function (items) {
                          setTimeout(function () {
                              if ( jQuery("#hatena-user-comment").html( items != null ? $jtemplates.get(items, null, window)
                                                                                      : no_comment ).html() == "" )
                              {
                                   jQuery("#hatena-user-comment").html( no_comment );
                              }
                          }, 1);
                 }
           },
           "buzzurl" : {
                 url      : "http://api.buzzurl.jp/api/posts/get/v1/json/",
                 callback : function (items) {
                          setTimeout(function () {
                               if ( jQuery("#buzzurl-user-comment").html( typeof items[0] != 'undefined' ? $jtemplates.get(items[0], null, window)
                                                                                                         : no_comment ).html() == "" )
                               {
                                    jQuery("#buzzurl-user-comment").html( no_comment );
                               }
                          }, 1);
                 }
           },
           "delicious" : {
                 url      : "http://badges.del.icio.us/feeds/json/url/data",
                 callback : function (items) {
                 }
           }
        }
    }
    // set
    var default_comment_msg = jQuery("#hatena-user-comment").html();
    var no_response = "<div class='no-comment-style'>リクエストがタイムアウトしました。</div>";
    // attach
    jQuery.each( contentsLoader, function (k,v) {
           jQuery("#" + k + "_button").click(function () {
                 // toggle
                 jQuery.each(contentsLoader, function (_k, _v) {
                       jQuery("#" + _k + "_button")
                           .attr("class", k == _k ? "load_active" : "");
                       jQuery("#" + _k + "-user-comment")
                           .css("display", k == _k ? "" : "none");
                       jQuery("." + _k + "-user-box-wrapper")
                           .css("display", k == _k ? "" : "none");
                 });
                 // load
                 var uc = jQuery("#" + k + "-user-comment");
                 if ( uc.html() == default_comment_msg ) {
                     setTimeout(function () {
                             if ( uc.html() == default_comment_msg )
                                 return uc.html( no_response );
                     }, 10000);
                     jQuery.get( contentsLoader[ k ][ "url" ], {
                          url      : location.href.replace(/http:\/\/clip\.(dev\.)?livedoor\.com\/page\//, "") || "http://www.livedoor.com/",
                          callback : "contentsLoader." + k + ".callback",
                          cb       : "contentsLoader." + k + ".callback",
                          random   : Math.random(36).toString(36).slice(-9)
                     }, null, "script");
                 }
           });
    });
});
