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

$(function(){
	serverId = getQueryString('serverId');
	if(serverId == null) serverId = 1;

	document.onmousedown = function(e){ 
        if(e.button==1){
            if (e && e.preventDefault) {//如果是FF下执行这个
                e.preventDefault();
            }else{ 
                window.event.returnValue = false;//如果是IE下执行这个
            }
            return false;
        };
    };
    
	var type = getQueryString('type')
	if(type != null) 
		itype = type
	else
		itype = 1;

	//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 = 18;
	switch(parseInt(fontSize)){
      case 22: index = 0; break;
      case 18: index = 1; break;
      case 14: index = 2; break;
    }
	size(true , fontSize, $('.date-div em:eq('+ index +')'));
	
	//type=0从森德进入 type!=0使用弹窗
	var themes = getCookie(themes_cookie+itype);
	if(itype==0){			
		if(themes == null)	themes = 'black'; //默认黑色背景	
		
		$('#Disclaimer').attr('class','Disclaimer0');		
	}else{
		if(themes == null)	themes = 'white'; //弹窗默认白色背景
		
		$('.wrapin').css('min-width','680px')

		$('#Disclaimer').attr('class','Disclaimer1');
	}
	$('.date-div .'+ themes).click();
 
})
 
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");

  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=/';
}