// はてなブックマーク用アイコン
var HATENABM_ICON = 'http://b.hatena.ne.jp/images/entry.gif';

// はてなブックマークの件数を表示する
function hatenabm_count ( url ) {
    if ( ! url ) url = location.protocol+'//'+location.hostname+location.pathname;
    var hatenabm_html = '<a href="http://b.hatena.ne.jp/entry/'+url+'"'+
        ' title="はてなブックマーク">'+
        '<img src="'+HATENABM_ICON+'" width="16" height="12" border="0"'+
        ' style="vertical-align:middle; margin-right:2px;">'+
        '<img border="0" src="http://b.hatena.ne.jp/entry/image/'+url+'"'+
        ' style="vertical-align:middle;"></a> ';
    document.write( hatenabm_html );
}

// livedoorクリップ用アイコン
var LIVEDOORCLIP_ICON = 'http://parts.blog.livedoor.jp/img/cmn/clip_16_16_w.gif';

// livedoorクリップの件数を表示する
function livedoorclip_count ( url ) {
    if ( ! url ) url = location.protocol+'//'+location.hostname+location.pathname;
    var livedoorclip_html = '<a href="http://clip.livedoor.com/page/'+url+'"'+
        ' title="livedoorクリップ">'+
        '<img src="'+LIVEDOORCLIP_ICON+'" width="16" height="16" border="0"'+
        ' style="vertical-align:middle; margin-right:2px;">'+
        '<img border="0" src="http://image.clip.livedoor.com/counter/'+url+'"'+
        ' style="vertical-align:middle;"></a> ';
    document.write( livedoorclip_html );
}

// del.icio.us用アイコン
var DELICIOUS_ICON = 'http://images.del.icio.us/static/img/delicious.small.gif';

// del.icio.us のブックマーク件数を表示する
function delicious_count ( url ) {
    if ( ! url ) url = location.protocol+'//'+location.hostname+location.pathname;
    var encurl = encodeURIComponent(url);
    var delicious_html = '<a href="http://del.icio.us/url/?url='+encurl+'"'+
        ' title="del.icio.us">'+
        '<img src="'+DELICIOUS_ICON+'" width="14" height="14" border="0"'+
        ' style="vertical-align:middle; margin-right:2px;">'+
        '<span id="delicious_count_'+encurl+'"'+
        ' style="font-family:Verdana,Arial,Helvetica;'+
        ' font-size:10px; vertical-align:middle;'+
        ' color:#FF6563; background:#FFF0F0;'+
        ' font-weight:bold; text-decoration:underline;"></span></a> ';
    document.write( delicious_html );

    // JSON URL Feeds を呼び出す <script> 要素を発行する
    var delicious_script = function () {
        var script = document.createElement( 'script' );
        script.type = 'text/javascript';
        script.charset = 'UTF-8';
        script.src = 'http://badges.del.icio.us/feeds/json/url/data?'+
            'url='+encurl+'&callback=delicious_callback';
        document.body.appendChild( script );
    };

    // prototype.js がある場合は Event.observe() を利用する
    if ( window.Event && Event.observe ) {
        Event.observe( window, 'load', delicious_script, false ); 
    } else {
        delicious_script();
    }
}

// JSON URL Feeds 取得時に呼び出されるコールバック関数
function delicious_callback( data ) {
    if ( ! data ) return;
    var first = data[0];
    if ( ! first ) return;

    // 『○people』を表示する span 要素を検索する
    var encurl = encodeURIComponent(first.url);
    var span = document.getElementById( 'delicious_count_'+encurl );
    if ( ! span ) return;

    // ブックマーク件数が10件を超えた場合は濃い赤にする
    if ( first.total_posts > 9 ) {
        span.style.color = '#FF0000';
        span.style.backgroundColor = '#FFCCCC';
    }

    // ブックマーク件数『○people』を挿入する
    var text = document.createTextNode( first.total_posts+' people ' )
    span.appendChild( text );
}