var themes_cookie = 'ytx_themes';
var font_size_cookie = 'ytx_font_size';
var itype = 1;
var serverId;

$(function(){
	//UTIL.getNewFrag("181", null, "tuijian");
	//颜色切换
	var initThemes = true;
	$("span[name='color']").click(function(){
		$(".date-div span").removeClass('blue-on orange-on white-on black-on')
		var cls = $(this).attr('class')
		$(this).addClass(cls+'-on')
		setTheme(cls)//更换皮肤		
		if(initThemes) {
			initThemes = false;
		}else{
			setCookie(themes_cookie+itype, cls);
		}
	})
	var fontSize = getCookie(font_size_cookie+itype);
	var index = 1;
	if(fontSize == null) fontSize = 12;
	switch(parseInt(fontSize)){
      case 22: index = 0; break;
      case 18: index = 1; break;
      case 12: index = 2; break;
    }
	size(true , fontSize, $('.date-div em:eq('+ index +')'));
	//type=0从森德进入 type!=0使用弹窗
	var themes = getCookie(themes_cookie+itype);
		if(themes == null)	themes = 'black'; //默认黑色背景	
		
		$('#Disclaimer').attr('class','Disclaimer0');		
 
	$('.date-div .'+ themes).click();
	$("#adimg").attr("src",httphost2+"ad/content.png");
 wkstock.autocloseTip=true;
wkstock.appendTip();  
wkstock.stockPlugin();   
 getContent(wkstock._GET('tid')); 
 $(".wrap").height($(window).height()-70);
 window.onresize=function(){
 $(".wrap").height($(window).height()-70);
 }
})
 
function setTheme(title){  
  var i, a;   
  if (title){ 
    for(i=0; (a = document.getElementsByTagName('link')[i]); i++){ 
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title')){
	       a.disabled = true;   
  	    if(a.getAttribute('title') == title) a.disabled = false;  
      }   
    }
    $('.div-intro *').css("color",$('.div-intro').css("color"))
  }
}

function size(init, size,obj){
  $('.date-div .em-b').removeClass('em-b');
  $(obj).addClass('em-b'); 
  $('.Editorials').css("font-size",(parseInt(size) + 4) + "px"); 
  $('.div-intro,.div-intro *').css("font-size",size + "px");
 // $(".h3-title").css("font-size",size + "px");
  if(!init)  setCookie(font_size_cookie+itype, size);
};

function getQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]); return null;
}

function getCookie(cookieId){
    var arrcookie = document.cookie.split("; ");
    for(var i=0; i<arrcookie.length; i++){
        var arr = arrcookie[i].split("=");
        if(cookieId == arr[0]){
            return arr[1];
        }
    }
    return null;
}

function setCookie(id, value){
	var date = new Date(); 
	var expiresDays=30;
	date.setTime(date.getTime()+expiresDays*24*3600*1000);

	document.cookie = id + "="+ value+';expires="+date.toGMTString();path=/';
}

  
var ajaxdata=null;
function getContent(tid) { 
	if(ajaxdata!=null){
		ajaxdata.abort();
		ajaxdata=null;
	}  
	ajaxdata=$.post(wkstock.host+"news/content/"+tid+"?callback=",function(json) {  
		if (json.a['title'] !="") { 
			 document.title=json.a.title;
				$(".h3-title").html(json.a['title']);
				$("#sj").html(json.a['createtime']);
	 		    $(".div-intro").html(json.ac['content']);  
	 		    $("[stockCode1]").after(function(){  return "<span onclick=\"wkstock.addselfstock('"+$(this).attr("stockCode1")+"')\" title=\"\u52a0\u5165\u81ea\u9009\u80a1\" style=\"cursor:pointer;color:#464646;font-size:10px;\">\u81ea</span><span title=\"\u67e5\u770b\u9898\u6750\u6982\u5ff5\" style=\"cursor:pointer;color:#0000FF;font-size:12px;\" onclick=\"wkstock.getTc('"+$(this).attr("stockCode1")+"')\">\u9898</span>";});
	 			$("[stockCode2]").after(function(){ return "<span onclick=\"wkstock.addselfstock('"+$(this).attr("stockCode2")+"')\" title=\"\u52a0\u5165\u81ea\u9009\u80a1\" style=\"cursor:pointer;color:#464646;font-size:10px;\">\u81ea</span><span title=\"\u67e5\u770b\u9898\u6750\u6982\u5ff5\" style=\"cursor:pointer;color:#0000FF;font-size:12px;\" onclick=\"wkstock.getTc('"+$(this).attr("stockCode2")+"')\">\u9898</span>";});
	 		 wkstock.autocloseTip=true;
			 wkstock.appendTip();  
			 wkstock.stockPlugin({pid:'379'}); 
		}else $(".div-intro").html('\u6682\u65e0\u4fe1\u606f');
		},"jsonp"); 
 return false;
}; 

 