/*
 * 
 * 详情页 google afc 广告
 * 
 * 上下两栏,显示版本 -r13747
 * 
 */

function google_ad_request_done(google_ads)
{
	var googleADCount = google_ads.length;
	if (googleADCount <= 0)
	{
		return;
	}

	var ads1 = ads2 = "<div class='hackDiv'>&nbsp;</div><div class='GcnAD_detail_title'><a href='" + google_info.feedback_url + "' target='_blank' >Google提供的广告</a></div>";
	var adsBlock1 = adsBlock2 = 0;
	var extend_class = '';
	//if (google_ads[0].type="text") 
	//{
		for(var i = 0; i < 2; i++)
		{
			if (typeof(google_ads[i]) != "undefined")
			{
                if ( i == 1) extend_class= "nbod";
				
				ads1 += '<dl class="GcnAD_cont ' + extend_class + '">' + 
					'<dt><a href="' + google_ads[i].url + '" target="_blank" >' + google_ads[i].line1 + 
					'</a></dt><dd>' + google_ads[i].line2  + '&nbsp;&nbsp;' + google_ads[i].line3 + 
					'</dd><dd><a class="GcnAD_adds" target="_blank" href="' + google_ads[i].url + 
					'">' + google_ads[i].visible_url + '</a></dd></dl>';
				adsBlock1 = 1;
			}
		}
	//}
	
    GJ.use('jquery', function(){
        var $obj4 = $('#GcnADId4'), 
            $obj1 = $('#GcnADId1'), 
            $obj  = adsBlock1 ? ($obj4.size() > 0 ? $obj4 : ($obj1.size() > 0 ? $obj1 : null) ) : null;
        if ($obj) {
            $obj.html(ads1).css({display : 'block'});

            if (window.tuan_config) {
                //取消团购广告
                return ;

                var tuan_obj;
                GJ.use('js/app/tuan/interface.js', function() {
                    function setDateHtml(expt, isDone) {
                        try {
                            var days = hours = minutes = 0;
                            if (expt > 0) {
                                var day_seconds = 60 * 60 * 24;
                                days = Math.floor(expt / day_seconds);
                                hours = Math.floor((expt - days * day_seconds) / 3600);
                                minutes = Math.floor((expt - days * day_seconds - hours * 3600) / 60);
                                seconds = Math.floor(expt % 60);
                            }
                            if (minutes > 0) {
                                if (parseInt(hours) < 10) hours = "0" + hours;
                                if (parseInt(minutes) < 10) minutes = "0" + minutes;
                                var dateInner = "还有 ";
                                if (days > 0) {
                                    dateInner += "<span>" + days + "天</span>";
                                }
                                dateInner += "<span>" + hours + "时" + minutes + "分<span> 结束";

                                $("#id_ad_tuan_day").html(dateInner);
                            }
                        } catch(err) { }
                    }

                    GJ.tuan.getCityDeals(tuan_config.cityId, callback);
                    function callback(data) {
                        var tuanHtml = "";
                        try {
                            var retDate = eval(data);
                            var isDone = (retDate.result == 1 && (retDate.display_order == 9999 || retDate.display_order == 99));
                            var title = retDate.mini_title; //retDate.title.length > 20 ? retDate.title.substring(0, 20).replace(/\d+$/, '') : retDate.title;
                            var price = retDate.groupon_price.length > 6 ? retDate.groupon_price.substring(0, 6).replace(/0+$/, '').replace(/\.$/, '') : retDate.groupon_price.replace(/0+$/, '').replace(/\.$/, '');
                            var origPrice = retDate.market_price.length > 6 ? retDate.market_price.substring(0, 6).replace(/0+$/, '').replace(/\.$/, '') : retDate.market_price.replace(/0+$/, '').replace(/\.$/, '');

                            
                            var id = GJ.guid(), $div = $('<div id="' + id + '"></div>');
                            tuan_html = '<dl class="GcnAD_cont nbod">' + 
                                        '   <dt><a target="_blank" title="' + title + '" href="http://tuan.ganji.com/' + tuan_config.cityDomain + '?f=xiangqing">' + title + '&gt;&gt;</a></dt>' + 
                                        '   <dd>现价<span class="price">' + price + '</span>元 原价<s>' + origPrice + '</s>元，已有 ' + retDate.now_number + ' 人购买<br /><span id="id_ad_tuan_day"></span></dd>' + 
                                        '   <dd><a class="GcnAD_adds" target="_blank" href="http://tuan.ganji.com/' + tuan_config.cityDomain + '?f=xiangqing">http://tuan.ganji.com/' + tuan_config.cityDomain + '/</a></dd>' + 
                                        '</dl>';
                            $(document.body).prepend($div);
                            $div.css({position:'absolute', left:-3000, top:-3000});
                            $div.append(tuan_html);
                            tuan_obj = $('#' + id).children()[0];

                            var expt = retDate.expire_time;
                            setDateHtml(expt, isDone);                            

                            var chd = $obj.children('dl');
                            if (chd.length > 1) {
                                $(chd[chd.length - 1]).remove();
                            }
                            $obj[0].appendChild(tuan_obj);
                        } catch(err) { }
                    }
                });
            }
        }
    });

	return;
}


if(typeof(detailAfcCount) =="undefined" || !detailAfcCount)
	detailAfcCount = 6;

detailAfcCount = 6;

google_ad_client = "pub-1496944590674366"; 
google_ad_channel = detailAfcChannelId;
google_ad_output = 'js';
google_max_num_ads = detailAfcCount;
google_ad_type = 'text';
google_gl = 'CN';
google_language = 'zh-CN';
google_encoding = 'utf8';
google_safe = 'high';
google_adtest = 'off';
google_ad_section = 'default';
google_feedback = 'on';

