var jquery_loader = 'http://www.yosukesugahara.com/diary/img/ajax-loader.gif';var json_search_data = 'http://www.yosukesugahara.com/diary/search_data.txt';var json_search_keyword   = '';var json_search_is_loaded = false;var json_search_entries;/*レイアウト*/function Layout(){$("#grid-content .item").biggerlink();$("#grid-content").vgrid({easeing: "easeOutQuint",time: 400,delay: 20});}/*検索*/function json_search_archive(){var result_data = new Array();json_search_keyword = json_search_keyword.replace(/([\/\\\.\*\+\?\|\(\)\[\]\{\}\$\^])/g, "\\$1");json_search_keyword = json_search_keyword.replace(/( +|　+)/, ' ');json_search_keyword = json_search_keyword.replace(/( |　)$/, '');var keywords = json_search_keyword.split(/ |　/);var key      = new Array();for (var i = 0;i < keywords.length;i++){key[key.length] = new RegExp(keywords[i], "i");}for (var i = 0;i < json_search_entries.length - 1;i++){var is_match = true;for (var j = 0;j < key.length;j++){var res_body  = key[j].exec( json_search_entries[i].body );var res_title = key[j].exec( json_search_entries[i].title );if (!res_body && !res_title){is_match = false;}}if (is_match){result_data[result_data.length] = json_search_entries[i];}}var result_html = '';if (result_data.length == 0){/*検索結果が無い場合*/result_html = '<div class="item_navi_goback"><a href="http://www.yosukesugahara.com/diary/" accesskey="1"><img alt="Diary by YosukeSugahara" src="/diary/img/diary_logo.gif" width="196" height="420" /></a></div><div class="item_saisin_kensaku"><div class="item_saisin_layout"><div class="ti_search"><img alt="latest entry" src="/diary/img/ti_serch.gif" width="350" height="21" /></div><div class="kensaku_hit">「' + json_search_keyword + '」に一致する情報は見つかりませんでした。</div><form action="javascript:json_search();" onsubmit="return checkSpaceOnly()"><input type="text" class="kensaku_text" id="search_box" value="" /><span class="btn_serch"><input name="submit" type="image" id="search_button" value="検索" src="/diary/img/btn_serch.gif" width="90" height="22" /></span></form></div></div><div class="item_navi_goback"><a href="#" title="Go Back Page" onclick="location.reload(true); return false;" onkeypress="location.reload(true); return false;"><img src="/diary/img/goback.gif" width="196" height="33" /></a></div>';}else{result_html = json_search_result_html(result_data, keywords);}$('#grid-content').css('height', 'auto').css('background-image', 'none').html(result_html);Layout();/*グリッドレイアウト！*/}/*検索結果表示*/function json_search_result_html(result_data, keywords){var html = '<div class="item_navi"><a href="http://www.yosukesugahara.com/diary/" accesskey="1"><img alt="Diary by YosukeSugahara" src="/diary/img/diary_logo.gif" width="196" height="420" /></a></div><div class="item_saisin_kensaku"><div class="item_saisin_layout"><div class="ti_search"><img alt="latest entry" src="/diary/img/ti_serch.gif" width="350" height="21" /></div><div class="kensaku_hit">※スペースでAND検索が出来ます。<br />「' + json_search_keyword + '」での検索結果は'+result_data.length + '件ヒットしました！</div><form action="javascript:json_search();" onsubmit="return checkSpaceOnly()"><input type="text" class="kensaku_text" id="search_box" value="' + json_search_keyword + '" /><span class="btn_serch"><input name="submit" type="image" id="search_button" value="検索" src="/diary/img/btn_serch.gif" width="90" height="22" /></span></form></div></div>';for (var i= 0;i < result_data.length;i++){html += '<div class="item"><div class="item_layout"><h2><a href="' + result_data[i].link + '#search_word=' + json_search_keyword + '" target="_self">' + highlight( trunc( result_data[i].title , keywords[0] ), keywords ) +'</a></h2>' +result_data[i].thumb_img +'<p>'+highlight( trunc( result_data[i].body, keywords[0] ), keywords ) +'</p>'+'<div class="date_layout"><span class="date_color">Date :'+result_data[i].date +'</span></div><div class="Cat_layout"><span class="Cat_color">Category :'+result_data[i].category+'</span></div>'+'</div></div>';}html += '<div class="item_navi_goback"><a href="#" title="Go Back Page" onclick="location.reload(true); return false;" onkeypress="location.reload(true); return false;"><img src="/diary/img/goback.gif" width="196" height="33" /></a></div>';return html;}function json_search(){json_search_keyword = $('input#search_box').val();/*$('#search-content').html('').css('height', '100px').css('background', 'transparent url(' + jquery_loader + ') no-repeat center center');*/if (json_search_is_loaded){json_search_archive();}else{$.ajax({url: json_search_data, type: 'GET', dataType: 'xml', timeout: 1500,error: function() {$('#search-content').css('height', 'auto').css('background-image', 'none').html('Error loading XML document');},complete: function(xml) {var data_string = xml.responseText;data_string         = data_string.replace(new RegExp('<.*?>', "i"), '');json_search_entries = eval(data_string);json_search_archive();json_search_is_loaded = true;}});}}function clear_block(blockid){$(blockid).html('');}function trunc( text, keyword ) {var key = new RegExp( keyword, "i" );var res = key.exec( text );if ( res ) {	var index  = res.index;	var length = res[0].length;	var start;	var end;	start = index - 20;	end = 55;	text = text.substring( start, index ) + text.substr( index, length ) + text.substr( index + length, end ) +'...';} else {text = text.substring( start, 50 );}return text;}function highlight( text, keywords ) {var keyword = '';for ( var i= 0; i<keywords.length; i++ ) {if ( i == keywords.length - 1 ) {keyword += keywords[i];} else {keyword += keywords[i] + '|'; }}/* patched by furyu  --- from --- ( referred to 'cocolog_ajax_search.js' )*//* original return text.replace( new RegExp( '(' + keyword + ')', "ig"), '<span style="background-color: #FFCC33;">' + "$1" + '</span>' );*/var	replaced_text = text.replace( new RegExp( '(' + keyword + ')', "ig"), '<span style="background-color: #ffff00;">' + "$1" + '</span>' );while( replaced_text.match( new RegExp( '(<[^>]+)<span style="background-color: #FFCC33;">(' + keyword + ')</span>(.*?>)', "ig") ) ) {replaced_text = replaced_text.replace( new RegExp( '(<[^>]+)<span style="background-color: #ffff00;">(' + keyword + ')</span>(.*?>)', "ig"), "$1$2$3" );}return replaced_text;/* patched by furyu  ---  to  ---*/}
