﻿/**
 * 新 delicious の被ブックマーク数を取得する
 * 要 md5.js by 光成滋生@サイボウズ・ラボ
 * 　　　http://labs.cybozu.co.jp/blog/mitsunari/2007/07/md5js_1.html
 * 
 * --------------------
 * Usage
 * <script type="text/JavaScript">
 * <!--
 * Delicious.dispPosts('delicious からの被ブックマーク数を調べたい URL');
 * // -->
 * </script>
 * --------------------
 */


// メイン
var Delicious = {

	urlProxy  : 'http://delicious.com/url/',
	imgUrl    : 'http://images.del.icio.us/static/img/delicious.gif',
	JSONProxy : 'http://feeds.delicious.com/v2/json/urlinfo/',

	// 表示
	dispPosts : function(url){

		var md5Code = CybozuLabs.MD5.calc(url);

		document.write(
			'<a href="' + this.urlProxy + md5Code + '">'
			+ '<img src="' + this.imgUrl + '" style="border:0;" width="18" height="18" alt="このエントリの delicious" />'
			+ '</a>'
		);
		document.write(
			'<script type="text/javascript" src="' + this.JSONProxy + md5Code +'?callback=jsonCallBack"></script>'
		);
	}

};


// コールバック関数
function jsonCallBack(json){
	if (json != ''){
		var posts = json[0].total_posts;
		if(posts != 0){
			document.write('[' + posts + ' users]');
		}
	}
};
