/* ld google ads */
google_ad_client = 'ca-livedoor-blog_js';
google_max_num_ads = '3';
google_ad_channel = 'blog_2';
google_ad_output = 'js';
google_ad_type = 'text';
google_language = 'ja';
google_country = 'JP';
google_encoding = 'euc-jp';
google_safe = 'high';

FromSearchEngine = false;
// FromSearchEngine = true; // Debug

(function(){
	var ref = document.referrer;
	if (/^http:\/\/search\.livedoor\.com\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/sf\.livedoor\.com\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/www\.google\.(co\.jp|com)\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/images\.google\.(co\.jp|com)/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/blogsearch\.google\.co\.jp\/blogsearch/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.yahoo\.co\.jp\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/blog-search\.yahoo\.co\.jp\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.goo\.ne\.jp\/web.jsp/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/blog\.search\.goo\.ne\.jp\/search_goo\/result/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.live\.com\/results\.aspx/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.msn\.co\.jp/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/www\.excite\.co\.jp\/search.gw/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/www\.baidu\.jp/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/blog\.baidu\.jp/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.nifty\.com\/websearch\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.nifty\.com\/blogsearch\/search/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/search\.www\.infoseek\.co\.jp\/Web/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/blogsearch\.fc2\.com/.test(ref)) FromSearchEngine = true;
	if (/^http:\/\/ask\.jp\/web\.asp/.test(ref)) FromSearchEngine = true;

    var rs = document.getElementById('ad_rs');
	if (FromSearchEngine) {
       if (rs) {
          google_max_num_ads = '8'; // FromSearchEngine, 7 = ad_rs2 + ad5 (new template)
          google_ad_channel = 'blog_search2';
       }
       else {
          google_max_num_ads = '8'; // FromSearchEngine, ad6 (old)
          google_ad_channel = 'blog_search';
       }
	} else {
       if (rs) {
          google_max_num_ads = '3'; // normally, ad_rs3 (new)
          google_ad_channel = 'exp1';
       } else {
          google_max_num_ads = '3'; // normally, ad5 (old)
          google_ad_channel = 'blog_2';
       }
    }
})();

function google_ad_request_done(google_ads) {
	var s = '';
	var i;
	if (google_ads.length == 0)  return;
    var format_ads = function (ads, addiv, adtype){
	   return '<div class="adbox" style="cursor: pointer; margin: 5px; padding: 2px 0 2px 18px;" onclick="javascript:'
        + 'if(typeof(blog_counter_adtrk) == \'function\') { blog_counter_adtrk(\''+addiv+'\', \'' + adtype + '\')};'
        + 'window.location.href=\''
		+ ads.url + '\';" onmouseover="adsHover(this,1);" onmouseout="adsHover(this,0);">' 
		+ '<div class="adtop" style="white-space: nowrap; overflow: hidden; width: 100%;"><a class="adtitle" style="text-decoration:none;">'
		+ '<span style="font-size: 14px; font-weight: bold; text-decoration: underline; line-height:200%;">' + ads.line1 + '</span></a>' 
		+ '<a class="adurl" style="text-decoration:none;margin-left:10px;">' 
		+ '<span style="font-size: 11px;">' + ads.visible_url + '</span></a></div>'
 		+ '<a class="addescription" style="text-decoration:none;">'
 		+ '<span style="font-size: 12px;">' + ads.line2 + '&nbsp;' + ads.line3 + '</span></a></div>';
	}

	var len = google_ads.length;

	var rs = document.getElementById('ad_rs');
	if (FromSearchEngine && google_ads.length > 3 && rs) {
		var s2_num = 0;
		var s2 = '<div class="gAdsense" id="gAdsense_google_jp2" style="margin: 0 auto; padding: 5px; text-align: left;">' +
     			 '<div style="margin:0 15px; font-size: 11px;"><a href="http://www.google.co.jp/intl/ja/ads/" class="adld">Ads by Google<\
/a></div>';
		for(i=3; i < len; i++) {
	        s2 += format_ads(google_ads[i], 'ad', 'google');
			s2_num++;
		}
		len -= s2_num;
		s2 += '</div>';
	}

	s +='<div class="gAdsense" id="gAdsense_google_jp" style="margin: 0 auto; padding: 5px; text-align: left;">' +
	'<div style="margin:0 15px; font-size: 11px;"><a href="http://www.google.co.jp/intl/ja/ads/" class="adld">Ads by Google</a></div>';
	for(i=0; i < len; i++) {
        s += format_ads(google_ads[i], (FromSearchEngine ? 'ad_rs' : 'ad'), 'google');
	}
	s +='</div>';

	if (FromSearchEngine) {
		var ad = document.getElementById('ad');
		if (rs) { 
           rs.innerHTML =  s;
           rs.style['display'] = 'block';
        }
		else { document.write(s); }
		if (ad && s2) { ad.innerHTML = s2; }
	}
	else { document.write(s); }
	return;
}
function adsHover(e,f){
	e.style.background = f ? '#ffffbb' : '';
	e.style.border = f ? '1px solid #ffffbb' : '0';
	e.style.padding = f ? '1px 0 1px 17px' : '2px 0 2px 18px';
	e.className = f ? 'adhover' : 'adbox';
}
