var makotokw = {
	theme:'http://www.makotokw.com/theme/dinoco/',
	useCustomSearch:true
};
(function($) {
	function trim(s) {
		if (s) {
			s = s.replace(/\t|\n|\r\n/g, '');
			s = s.replace(/^[ ]+|[ ]+$/g, '');
		}
		return s;
	}
	function reply(authorId, commentId, commentBox) {
		var author = $('#'+authorId).html();
		var s = '<a href="#' + commentId + '">@' + trim(author) + ' </a> \n';
		appendReply(s, commentBox);
	}
	
	function quote(authorId, commentId, commentBodyId, commentBox) {
		var author = $('#'+authorId).html();
		var comment = $('#'+commentBodyId).html();
	
		var s = '<blockquote cite="#' + commentBodyId + '">';
		s += '\n<strong><a href="#' + commentId + '">' + trim(author) + '</a> :</strong>';
		s += comment.replace(/\t/g, "");
		s += '</blockquote>\n';
		insertQuote(s, commentBox);
	}
	
	function appendReply(s, id) {
		var $field = $('#'+id);
		var v = $field.val() || '';
		if (v.indexOf(s) > -1) {
			alert("You've already appended this reply!");
			return false;
		}
	
		if (v.replace(/\s|\t|\n/g, "") == '') {
			$field.val(s);
		} else {
			$field.val(v.replace(/[\n]*$/g, "") + '\n\n' + s);
		}
		$field.focus();
	}
	
	function insertQuote(s, id) {
		var $field = $('#'+id);
		var v = $field.val();
		$field.val(v+s);
		$field.focus();
	}
	this.reply = reply;
	this.quote = quote;

}).apply(makotokw,[jQuery]);

(function($){
	$(document).ready(function() {
		var theme = makotokw.theme;
		// google custom search
		if (makotokw.useCustomSearch) {
			try {
				var cseId = '003122074834180947232:omul0da14we';
				var box = document.getElementById('searchbox_'+cseId);
				if (!box) box = document.getElementById('searchbox_demo');
				if (box && box.q) {
					var q = box.q, n = navigator, l = location, r = document.getElementById("results_"+cseId);
					if (n.platform == 'Win32') q.style.cssText = '';
					CSEOverlay(cseId, box, r);
				}
			} catch (e) {}
		}
		// pretyprint
		if ('function' == typeof(prettyPrint)) {
			prettyPrint();
		}
		// lightbox
		$('a[rel=lightbox]').lightBox({
				imageLoading:			theme+'images/lightbox/ico-loading.gif',		// (string) Path and the name of the loading icon
				imageBtnPrev:			theme+'images/lightbox/btn-prev.gif',			// (string) Path and the name of the prev button image
				imageBtnNext:			theme+'images/lightbox/btn-next.gif',			// (string) Path and the name of the next button image
				imageBtnClose:			theme+'images/lightbox/btn-close.gif',		// (string) Path and the name of the close btn
				imageBlank:				theme+'images/lightbox/blank.gif'			// (string) Path and the name of a blank image (one pixel)
		});
	});
})(jQuery);

/*
if (makotokw.useAwaseteYomitai) {
	window['awasete_yomitai'] = function awasete_yomitai(blogs) {
		// var blogs = [{titile:,url:,favicon:,more:},...];
		var el = document.getElementById('awasete-blog-list');
		if (el) {
			var max = 10, a = [], len = Math.min(max,blogs.length);
			for (var i=0; i<len; i++) {
				var b = blogs[i];
				a.push('<li style="background:transparent url('+b.favicon+') no-repeat left"><a href='+b.url+'>'+b.title+'<\/a><\/li>');
			}
			el.innerHTML = a.join('');
		}
	}
}*/
