function kcap(json) {
	var box = $('#bpkcap');
	$(json.results).each(function(i, v) {
		v.jp_created_at = dateJp(v.created_at);
		var html = template('<li style="list-style:none;text-align:left;">\
		<span style="display:block;height:30px;padding-bottom:3px;margin-top:3px;line-height:12px;background:url(http://www.kcap.jp\/bp\/bpbg.png) right bottom no-repeat;text-align:left;">\
		<a href="http:\/\/twitter.com\/#{from_user}"><img src="#{profile_image_url}" style="border:none;float:left;margin-right:3px;" width="30" height="30" alt="#{from_user}" \/><\/a>\
		<a href="http://twitter.com/#{from_user}" style="text-decoration:none;color:#cc0066">#{from_user}<\/a>\
		<span style="margin-left:3px;text-align:left;color:#222"">#{jp_created_at}<\/span><\/span>\
		<span style="clear:both;display:block;padding:3px 3px 0 3px;height:24px;overflow:hidden;line-height:12px;background:#000;color:#fff;">#{text}<\/span>\
		<span style="display:block;padding:3px;line-height:12px;background:#000;color:#fff;text-align:right;"><a href="http://twitter.com/#{from_user}" style="text-decoration:none;color:#cc0066">more...<\/a><\/span>\
		<\/li>\
		', v);
	box.append(html);
	});
	document.write('\
	<div style="width:160px;margin:0;text-align:center;font-size:10px;background:url(http://www.kcap.jp/bp/bpbg.png) 0 -23px no-repeat;padding:3px 0;color:#222">Powered by <a href="http://www.kcap.jp/" style="text-decoration:none;color:#cc0066"">kcap.jp<\/a><\/div>\
	'); 
}
function template(str, obj, replacement) {
	return str.replace(/#\{(.+?)\}/g, function() {
		try {
			return eval('obj.' + arguments[1]);
		} catch (e) {
			return replacement ? replacement : '';
		};
	});
}
function dateJp(dateStr){
	var d = dateStr.split(" ");
	var post_date = d[0] + " " + d[2] + " " + d[1] + " " + d[3] + " " + d[4];
	var date = new Date(post_date);
	date.setHours(date.getHours() + 9);
	return date.toString();
}
$(function () {
	$('ul#bpkcap').ss();
});
(function ($) {
$.fn.ss = function (limit, interval) {
	limit = limit || 3;
	interval = interval || 10000;
	return this.each(function () {
		var $list = $(this),
			items = [],
			currentItem = limit,
			total = 0,
			height = $list.find('> li:first').height();
		$list.find('> li').each(function () {
			items.push('<li>' + $(this).html() + '</li>');
		});
		total = items.length;
		$list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();
		function sslide() {
			var $insert = $(items[currentItem]).css({
				height : 0,
				opacity : 0,
				display : 'none'
			}).prependTo($list);
			$list.find('> li:last').animate({ opacity : 0}, 1000, function () {
				$insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);
					$(this).remove();
				});
			currentItem++;
			if (currentItem >= total) {
				currentItem = 0;
			}
			setTimeout(sslide, interval)
		}
		sslide();
	});
};
})(jQuery);


