/**
 * 右侧栏头条调用
 * woody 16.4.28
 */

if(typeof $ != 'undefined'){
	var rdata = [];
	rdata.push('news,xinwen,.newsRight');
	rdata.push('chanye,chanye,#rightDiv');
	rdata.push('hd,huodong,.con_rt');
	rdata.push('xin,xinyou,.cont_rt');
	rdata.push('fahao,fahao2017,.bodyRight');
	rdata.push('youxiku,youxiku,.w250 > .bStyle');
	rdata.push('c,c,.this_300');
	$(function(){
		var host = window.location.host;
		var api_url = 'http://www.07073.com/api/toutiao.php';
		var base_style = '<link href="http://m1.073img.com/ued2016/theTodayHeadlines/theTodayHeadlines.css" rel="stylesheet" type="text/css" />';
		var domains = host.split('.')[0];
		var inf, color='';
		
		if(domains == 'news'){
			//排除新闻首页
			if($('#xc1').length > 0){
				domains = '';
			}
		} else if(domains == 'huoying' || domains == 'www'){
			if($('.subSearch').length > 0){
				//游戏库
				domains = 'youxiku';
			} else if($('.this_bgall').length > 0){
				domains = 'c';
				color = $('.this_message_tit dt').css('border-color')
				color = '<style>.theTodayHeadlinesMaxing p a:hover { background-color: '+color+'; color: '+color+'; }.theTodayHeadlinesMaxing p a:hover, .theTodayHeadlinesListx dt { background-color: '+color+'; }.theTodayHeadlinesListx dt, .theTodayHeadlinesListx dd, .theTodayHeadlinesTitlex { border-color: '+color+'; }</style>';
			}
		}
		
		for(var i=0; i<rdata.length; i++){
			if(rdata[i].indexOf(domains+',') == 0){
				inf = rdata[i].split(',');
				break;
			}
		}
		
		
		if(inf && inf.length == 3){
			$('body').append(base_style);
			$('body').append('<link href="http://m1.073img.com/ued2016/theTodayHeadlines/'+inf[1]+'.css" rel="stylesheet" type="text/css" />');
			if(color != ''){
				$('body').append(color);
			}
			$.ajax({
				 type: "get",
				 async: false,
				 url: api_url,
				 dataType: "jsonp",
				 jsonp: "callback",
				 jsonpCallback:"_cb",
				 success: function(json){
					 window.setTimeout(function(){
						 if(domains == 'youxiku'){
							 $(inf[2]).eq(0).append(json.html);
						 } else {
							 $(inf[2]).eq(0).prepend(json.html);
						 }
					 }, 500);
				 },
				 error: function(){
					 //just do nothing
				 }
		    });
		}
	});
	function rndTT(show_num){
		var dl = $('.theTodayHeadlinesListx dl').hide();
		var l, n = 0;
		while(1){
			l = Math.floor(Math.random()*(dl.length));
			if(dl.eq(l).is(':hidden')){
				dl.eq(l).show();
				n ++;
			}
			if(n == show_num){
				break;
			}
		}
	}
}

